Jump to content
  • Advertisement
ryt

C++ Error with copy/move constructors and assignments

Recommended Posts

I created my simple Float2 struct and defined it like this:

struct Float2
{
	float _x;
	float _y;

	Float2() {}
	Float2(float x, float y) { _x = x; _y = y; }
	Float2(const Float2& copy) = default;
	Float2& operator=(const Float2& copy) = default;
	Float2(Float2&& move) = default;
	Float2& opeartor=(Float2&& move) = default;
}

On last line for move assignment operator I get an ambiguous error and I can't compile. The error under "move" is saying that it should be preceded with ")" and error under "=" is saying that is expecting an expression.
Why is this, did I do something wrong?

Edit: Oh, on last line I wrote "opeartor" instead of "operator". BTW, is this ok how I created my struct? Are all the defaults necessary? I want my struct to use move when applicable instead of copy so I can get faster operations like addition.

Edited by ryt

Share this post


Link to post
Share on other sites
Advertisement
9 minutes ago, ryt said:

I created my simple Float2 struct and defined it like this:


struct Float2
{
	float _x;
	float _y;

	Float2() {}
	Float2(float x, float y) { _x = x; _y = y; }
	Float2(const Float2& copy) = default;
	Float2& operator=(const Float2& copy) = default;
	Float2(Float2&& move) = default;
	Float2& opeartor=(Float2&& move) = default;
}

On last line for move assignment operator I get an ambiguous error and I can't compile.
Why is this, did I do something wrong?

On your last line you have a spelling error. Should be 

operator

you have opeartor

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!