Anonymous
#pragma once #include"RYMath" #include "RYFrame" #include<vector> namespace RY{ class Bullet{ public: Frame finalAnimation; const Angle &InternalAngle; float vel = 1; float angle = 0; Dot<float> vector; Dot<float> position; Dot<float> target; Bullet(Angle &angle,Frame finalAnimation,float Velocity=1.f): position(Dot<float>(angle.originX,angle.originY)), vector(angle.calculateVector()), vel(Velocity), angle(angle.calculateAngle()), InternalAngle(angle), target(angle.getTarget()), finalAnimation(finalAnimation) {} void setTarget(const Dot<> &newTarget){ vector=Dots2Vector(InternalAngle.getOrigin(),newTarget); } bool update(float deltaTime = 1.f, bool updateVector = false){ Dot length = target-position; if(updateVector?true:vector>Dot(0.f,0.f)?length>Dot(0,0):length<Dot(0,0)){ if(updateVector) vector=Dots2Vector(InternalAngle.getOrigin(),InternalAngle.getTarget()); position+=(vector*vel*deltaTime); }else{ return true; } return false; } }; std::vector<Bullet> Bullets; }
Anonymous
#pragma once #include"RYMath" #include "RYFrame" #include<vector> namespace RY{ class Bullet{ public: Frame finalAnimation; const Angle &InternalAngle; float vel = 1; float angle = 0; Dot<float> vector; Dot<float> position; Dot<float> target; Bullet(Angle &angle,Frame finalAnimation,float Velocity=1.f): position(Dot<float>(angle.originX,angle.originY)), vector(angle.calculateVector()), vel(Velocity), angle(angle.calculateAngle()), InternalAngle(angle), target(angle.getTarget()), finalAnimation(finalAnimation) {} void setTarget(const Dot<> &newTarget){ vector=Dots2Vector(InternalAngle.getOrigin(),newTarget); } bool update(float deltaTime = 1.f, bool updateVector = false){ Dot length = target-position; if(updateVector?true:vector>Dot(0.f,0.f)?length>Dot(0,0):length<Dot(0,0)){ if(updateVector) vector=Dots2Vector(InternalAngle.getOrigin(),InternalAngle.getTarget()); position+=(vector*vel*deltaTime); }else{ return true; } return false; } }; std::vector<Bullet> Bullets; }
error: use of deleted function 'RY::Bullet& RY::Bullet::operator=(RY::Bullet&&)' 400 | *result = std::move(*first); | This is from your error message. In C++14, there was a problem with the standard wording for erase function on vector<T> which required T to be MoveAssignable and also that the elements past the element to be erased will be move assigned. This was corrected later in C++17. So I suspected that was the issue. Here is the quote from the C++14 standard: std::vector::erase ([vector.modifiers]: Effects: ... Complexity: The destructor of T is called the number of times equal to the number of the elements erased, but the move assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements. Throws: Nothing unless an exception is thrown by the move assignment operator of T.
MᏫᎻᎯᎷᎷᎬᎠ
https://github.com/carbon-language/carbon-lang
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
I'm starting to understand a little bit and I'm using c++20
The problem is that your class Ry::Bullet has a constant reference data member which causes the assignment operator to be synthesized as deleted. There will be no move assignment operator as you haven't requested it (from the code snippet you showed). If you request it explicitly, that will also be synthesized as deleted. When you call erase, the vector's implementation will try to use the move assignment operator to move the elements past the element being deleted if the move assignment operator is noexcept (since C++17. C++14 had this wrongly worded). If it can throw exceptions, the copy assignment operator would be used as a fallback. But in your case the copy assignment operator is a deleted operation. So you can't call erase on a vector holding such elements.
#
K&r is outdated?
Anonymous
Hi! I need help please, so I trying create a library, but when run the compiler return an error: g++ main.cpp /usr/bin/ld: /tmp/cc0ufRYL.o: in function `main': main.cpp:(.text+0x15): undefined reference to `nDividers_PN(int)' collect2: error: ld returned 1 exit status You can find it on my github: https://github.com/Leumim2020/lib_divisorsPN/tree/main/lib_divisoresPN
Anonymous
you have a main in your library ?
If I have a file main.cpp?
Sajjad
Yes, I have
library is not executable
Anonymous
library is not executable
Yes, I know, but how do solve this problem?
Anonymous
library is not executable
You've downloaded and tested the code?
Anonymous
no i didnt
When I call the nDividers_PN(a); the function does not run, in my program main. I created a file .h and second file for prototype cpp and includes at file main.cpp. For test, but it's not executed.
Anonymous
You have to do g++ main.cpp main2.cpp
I must execute the file main.cpp and main2.cpp in only line?
Anonymous
I must execute the file main.cpp and main2.cpp in only line?
No you can compile them separately but when you link them, you must tell the linker where to find the required object files. I would suggest that you read about the different phases of compilation in the Resources section of this channel. That would help you understand
Anonymous
Thanks, but what channel?
Anonymous
how can I make assignment operator not be deleted?
By defining your own assignment operator. But remember that when you have a const reference member, the semantics of assignment itself changes. You can't change the const reference member. So what would it mean to assign another object with a different angle to an object when the angle cannot be changed.
Ибраги́м
https://github.com/carbon-language/carbon-lang
Anonymous
https://github.com/carbon-language/carbon-lang
This was bound to happen. With the C++ standards committee insisting on non ABI breaking changes alone, people were bound to look for something that has the appearance of a more modern language like Kotlin, Rust or Go. The GitHub page specifically says that even C++20 looks like an archaic language with concepts specifically being pointed out as being tedious.
Anonymous
C++20 concepts? Tedious? They are pretty much compile time predicates (you can actually use them as bool)
The way you need to describe them is what is tedious. Not how they are evaluated by the compiler. Look at the examples provide of how they would look like in Carbon
trimbleyy
How to solve username and password for github repos clone via termux
Dima
lol
pavel
You need make token
Ludovic 'Archivist'
The way you need to describe them is what is tedious. Not how they are evaluated by the compiler. Look at the examples provide of how they would look like in Carbon
I do not find it to be a less tedious syntax. I find it to be a different one, implemented very differently, and reflecting different goals. It doesn't have concepts in the same sense as C++ does, it has type erased generics with constraints comprehensions, which do something completely different and solve a similar but not identical problem
Ludovic 'Archivist'
Also, I foresee problems in the bits of that syntax where erased types have overlapping but not related erasors
Anonymous
Hello, is there a friend we can learn programming in C language together?
Iwan
Hello, is there a friend we can learn programming in C language together?
I think we are all here learn C together, not python or php or anything else.
Anonymous
I keep getting an error trying to compile this:
Anonymous
concept bool Averageable() { return std::is_default_constructible<T>::value && requires (T a, T b) { { a += b } -> T; { a / size_t{ 1 } } -> T; }; }
Anonymous
note: 'concept' only available with '-std=c++20' or '-fconcepts'
Anonymous
I don't know why
кар карыч
How can I make a delay without pausing the program? on windows.h
кар карыч
Help plz (
pavel
Sounds strange
кар карыч
How to do waiting in C++ ?
Iwan
How to do waiting in C++ ?
Why you need to delay without pausing?
кар карыч
Because I am developing a script for a game, and when using sleep, the game is pausing
кар карыч
windows
Anonymous
Good morning guys!
Anonymous
Because I am developing a script for a game, and when using sleep, the game is pausing
I don't know if I understood very well but are you trying to delay only a part of the code? a function for example? maybe thread or clock help you
кар карыч
clock?
pédroo
👋
Anonymous
I do not find it to be a less tedious syntax. I find it to be a different one, implemented very differently, and reflecting different goals. It doesn't have concepts in the same sense as C++ does, it has type erased generics with constraints comprehensions, which do something completely different and solve a similar but not identical problem
I do understand Type Erasure and that Generics in Carbon is similar to how it is in .Net and Java. Concepts in C++ 20 is a similar in nature to Interfaces in Carbon (meaning they serve the same purpose from the developer's point of view. What happens underneath is a different issue). In C++, concepts help the compiler evaluate whether template parameters meet certain constraints while retaining T's type. But requires a tad too much effort on the part of the user. Typically code that uses concepts doesn't really benefit much from retaining the type of the parameters. Agreed that C++ has this idea of template code not being instantiated until called and therefore you can instantiate templates with any types as long as you don't call an operation that the type does not support. This is what Concepts were meant to avoid and likely to lead to more friendly error messages instead of the error novels we get. So type erasure greatly helps here which unfortunately C++ doesn't do. For a use of a concept like say IsLessThanComparable, the code is unlikely to use much of the other properties of type T. So type erasure to IsLessThanComparable is a preferable alternative to the option that C++ has. This is a direction the standard committee cannot take which is what necessitates a language like Carbon in the first place which was my point to begin with.
Pavel
note: 'concept' only available with '-std=c++20' or '-fconcepts'
Did you pass one of these flags to the compiler? Otherwise, as it says, they won't be enabled
Anonymous
Hello guys! I want to know how to store a variable from int main() then use it for another function.
Anonymous
I searched a lot already. 😭
Amir.M
Hello guys! I want to know how to store a variable from int main() then use it for another function.
https://stackoverflow.com/questions/64033044/how-to-access-int-a-declared-in-main-in-another-function
Anonymous
I need more about loop statements
Anonymous
In c
Sajjad
how can i see what compiler replace with auto in compile time i want to switch a code from cpp 20 to cpp 17 wierdly :) gcc would be grate or even compiler explorer option
Anonymous
how can i see what compiler replace with auto in compile time i want to switch a code from cpp 20 to cpp 17 wierdly :) gcc would be grate or even compiler explorer option
Do you use an IDE? That should display the types inferred If not you can do something like this: template<typename T> struct InferredType; auto x = <something>; InferredType<decltype(x)> iType; The line above would give you a compiler error saying InferredType could not be defined (because it is an incomplete type) with the inferred type of x.
Anonymous
#include<iostream> #include<fstream> using namespace std; int main(){     std::ifstream inputFile("test.txt");     if(inputFile.good())         std::cout << inputFile.rdbuf()<<endl;     return 0; } This program outputs “Name: Beethoven Song: Moonlight Sonata” But my test .txt is clearly written as “Hello world “ How it comes to be Beethoven?
Anonymous
It looks like the debugger of vscode messed up the directory
.
#include<stdio.h> int main() { int a[6] = {11,23,44,21,32,89}; int i,j; for(i = 0 ; i < 3 ; i++) { for(j = i+1 ; j < 3 ; j++) { if(a[i] > a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; } } } for(i = 3 ; i < 6 ; i++) { for(j = i+1 ; i < 6 ; j++) { if(a[i] < a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; } } } for(i = 0 ; i < 6 ; i++) printf("%d ",a[i]); return 0; }
.
when am running this code it is saying segmentation default(core dumped)
.
how do i fix this?
Anonymous
Hey I want to start learning C++ am so new please what materials do I even need to start
Anonymous
My laptop is ready
Fetheddine
Or only code blocks (install mingw setup version)
Bl
Can someone explain usage of || please ? #include <stdio.h> int main() { // Write C code here int i,a=1,b=2,c=3; i= ++a |,| ++b |,| ++ c ; printf("%d %d %d %d",i,a,b,c); return 0; } *I used , between two of | , because telegram doesn't accept double |