CVertex &CVertex::operator = (CVertex &V)
{
setX(V.x);
setY(V.y);
setZ(V.z);
return *this;
}
Ive stayed away from operator Overloading by just writing Add and Copy functions. Though Ive noticed how it reduces development time. So, here I am. Thanks for the help,
Can you overload the = operator?
I cant seem to overload the = operator. I prototype(or whatever) like this:
inline CVertex &operator = (CVertex &V);
and then the function in like this:
I do not think you need the & in the function prottype or definition.
Also try and set your x,y,z variables withou calls to other functions (I''ve never tried to use a function insige an assignment overload before)
so the re-vised code would be:
Try that if that does not work, then the book I''m reading now is at fault, but then again so is 99% of most docs I read from Microsoft 8)
Also try and set your x,y,z variables withou calls to other functions (I''ve never tried to use a function insige an assignment overload before)
so the re-vised code would be:
CVertex CVertex::operator = (CVertex V){ x = V.x; y = V.y; z = V.z; return *this;}
Try that if that does not work, then the book I''m reading now is at fault, but then again so is 99% of most docs I read from Microsoft 8)
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Yeah, I usually dont use function to set it, though I thought it would be better OOP programming to set them Private. And there inlined so I dont think theres really any difference. Ill try it and get back to u
Heres the Error''s I get using my code or your code. Whenever I try to use Operator Overloading, this is what happens:
--------------------Configuration: Goliath1 - Win32 Debug--------------------
Compiling...
App.cpp
Skipping... (no relevant changes detected)
Box.cpp
Button.cpp
Character.cpp
Console.cpp
Control.cpp
Engine.cpp
Face.cpp
Font.cpp
general.cpp
main.cpp
Map.cpp
Menu.cpp
Object.cpp
Octree.cpp
Player.cpp
Script.cpp
Texture.cpp
Vertex.cpp
World.cpp
Linking...
Face.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
general.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
Octree.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
Debug/Goliath1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Goliath1.exe - 4 error(s), 0 warning(s)
--------------------Configuration: Goliath1 - Win32 Debug--------------------
Compiling...
App.cpp
Skipping... (no relevant changes detected)
Box.cpp
Button.cpp
Character.cpp
Console.cpp
Control.cpp
Engine.cpp
Face.cpp
Font.cpp
general.cpp
main.cpp
Map.cpp
Menu.cpp
Object.cpp
Octree.cpp
Player.cpp
Script.cpp
Texture.cpp
Vertex.cpp
World.cpp
Linking...
Face.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
general.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
Octree.obj : error LNK2001: unresolved external symbol "public: class CVertex __thiscall CVertex::operator=(class CVertex)" (??4CVertex@@QAE?AV0@V0@@Z)
Debug/Goliath1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Goliath1.exe - 4 error(s), 0 warning(s)
You can''t put inlined functions in the .CPP file. Limitation of the compiler. Also, there''s nothing wrong OOP wise with having class member functions directly access member variables, unless you feel that the purpose of those variables could change in later revisions of a class or in derived classes. But since you''re not likely to change or derive classes from CVertex..
-RWarden (roberte@maui.net)
-RWarden (roberte@maui.net)
Ok, then Ill just put the class code in the class Definition. Also, the code I put up would not of worked if x,y,z were private, i MEANT to put:
x = V.getx();
y = V.gety();
z = V.getz();
Thanks, and sorry for the confusion.
x = V.getx();
y = V.gety();
z = V.getz();
Thanks, and sorry for the confusion.
One object can access another object''s private members if they are the same class:
That''s perfectly legal and all right. To put it another way, a class is always mutual friends with itself.
-RWarden (roberte@maui.net)
class Foo{private: int var;public: void Func( Foo& bar ) { var = bar.var; }}
That''s perfectly legal and all right. To put it another way, a class is always mutual friends with itself.
-RWarden (roberte@maui.net)
Wait a sec...
First you prototype and then you define (I think that''s the right words) a inline function... I''m quite new to c++ and of what I know, when you define a function to be inline, you must define (or in case I''m using the wrong word, wright the "setx(V.x);...etc" code) right after you prototype the function (like in java).
So if the problem persists, take the inline keyword out and that''s the case, you just need to eliminate the CVertex::&operator=(CVertex &V).
Being punctual is only making your mistake on time...
Murphy
First you prototype and then you define (I think that''s the right words) a inline function... I''m quite new to c++ and of what I know, when you define a function to be inline, you must define (or in case I''m using the wrong word, wright the "setx(V.x);...etc" code) right after you prototype the function (like in java).
So if the problem persists, take the inline keyword out and that''s the case, you just need to eliminate the CVertex::&operator=(CVertex &V).
Being punctual is only making your mistake on time...
Murphy
Being punctual is only making your mistake on time...Murphy1 to 3 chefs make a good restaurant 100 chefs makes a McDonaldsTim Sweeney
OOOPS small typo
"the end is supposed to be "and if that''s the case" and not that obrigatory remark that was imposed...
"the end is supposed to be "and if that''s the case" and not that obrigatory remark that was imposed...
Being punctual is only making your mistake on time...Murphy1 to 3 chefs make a good restaurant 100 chefs makes a McDonaldsTim Sweeney
actually esap1, you can access private members because this is a member function.. and you want to include the &, because that''ll return a reference to the current object, instead of just a copy of it..
from the errors you posted, it looks like it can''t find the method definition... i can''t find anything wrong with the code you posted.. i get it to compile just fine...
from the errors you posted, it looks like it can''t find the method definition... i can''t find anything wrong with the code you posted.. i get it to compile just fine...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement