Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ziphnor

Weird link errors for operators

This topic is 5898 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im a bit confused by these link errors. As part of my Particle System, ive implemented a standard 3d vector class called Vector3D. Im getting these kind of link errors: ParticleSystem error LNK2005: "class Vector3D __cdecl operator+(class Vector3D const &,class Vector3D const &)" (??H@YA?AVVector3D@@ABV0@0@Z) already defined in main.obj These errors are ONLY for the operators that are defined OUTSIDE the class declaration(so for example it doesnt complain about operator+= etc, only +,-,*(twice for * because i made one with (double, vector) and one for (vector, double)). I would normally think such link errors had something to do with a lack of include guards but i DO use include guards, ie the Vector3D.h is build up like this: #ifndef VECTOR3D_H #define VECTOR3D_H class declaration operator declarartion #endif The amusing thing is that i dont get the error just anywhere. If i in main.cpp includes Vector3D.h i dont get any error, if i include Vector3D.h AND Particle.h(which in turm also includes Vector3D.h) i DONT get an error either. BUT if i include ParticleSystem.h(which includes Vector3D.h and Particle.h) then i do get the error. BUT if i REMOVE ParticleSystem.cpp from the project i dont get the link errors anymore(until i actually try to use a ParticleSystem at which time i get a link error refering to the ctor/dtor). I even tried outcommenting ALL the actual code in ParticleSystem.cpp, only leaving #include "ParticleSystem.h" in that file. This ALSO gives me the link error about the operators already being defined. If i also remove the include statement from ParticleSystem.cpp then i dont get the link error. The only difference i can tell between Particle.h and ParticleSystem.h is that Particle doesnt have an associated cpp file(its too simple for that). EDIT: If i make a Particle.cpp that just includes Particle.h then i get the same error AGAIN! So as soon as a h file that includes Vector3D.h is included in a cpp file(except for main.cpp) i get these errors.... argghh.. If ANYONE could drop me a hint about what could cause this, *please* do PS: Im using Visual C++ .NET.(and btw, i did try cleaning out the Debug dir etc).. [edited by - ziphnor on June 29, 2002 3:25:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Are you just declaring the function in the .h file? or are you both declaring & defining it in the .h file?

If you defining it in the header file, then you have to declare it as being either an inline or static function (or both).

If this doesn''t work or you''ve already tried this, then I''m not sure what else to say at the moment.

Share this post


Link to post
Share on other sites
Im both declaring and defining all the operators in the Vector3D.h...
And, damn it, you are right, i declared them inline and the problem went away.....
Thank you a whole lot!

Share this post


Link to post
Share on other sites

  • 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!