Skip to main content
gamedev.net
🔒 Locked

'operator=' unavailable ?

Started by edotorpedo Jun 10, 2002 at 3:07 PM 3 replies 450+ views
Original Post
edotorpedo
edotorpedo
OK, I have a class without any pointers, say Camera. Now I''m trying to do this: class world { public: void set(Camera); private: Camera cam; }; void world::set(Camera c) { cam = c; } So why does this give an error ''operator='' uavailable. The VC++6 compiler should be smart enough to create its own assignment operator for class Camera??? I don''t get it. edotorpedo
Edo
Dez
Dez
I think I know what you're talking about. When I get that messsage, it's usually because the class in question contains data members which are either constant or are reference variables.

The compiler's default assignment operator simply copies the memory from one object to the other, but it can't do that when there are either of these types of variables involved.

Try just changing them to pointers. The code might get a bit complex, so be careful.

[edited by - Dez on June 10, 2002 4:17:46 PM]
Palidine
Palidine
please post your code for the Camera class.
edotorpedo
edotorpedo

Thanks dez!,

The camera class does contain a constant! Still...why can''t this class be copied? Shouldn''t be to hard to implement for a compiler.

Does anybody know this?

Thanks,

edotorpedo
Edo
Stoffel
Stoffel
Just a note: two copies are potentially occuring here, one in the assignment, and another when you pass in the Camera argument. You can keep the same semantics and remove the copying in the argument by changing your prototype to:

void world::set (const Camera &c);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.