Skip to main content
gamedev.net
🔒 Locked

Namespace problem

Started by p4n1c Jan 13, 2003 at 5:21 PM 23 replies 2k views
Original Post
p4n1c
p4n1c
I'm getting a linker error saying unresolved symbol: *edit: Broke the error into two lines so you don't have to scroll across*
error LNK2019: unresolved external symbol "public: void __thiscall OdinMath::Vector::operator=(class OdinMath::Vector const &)" 
(??4Vector@OdinMath@@QAEXABV01@@Z) referenced in function "public: void __thiscall OdinCamera::ViewMatrix(float)" (?ViewMatrix@OdinCamera@@QAEXM@Z)
  
When it has been defined already in the OdinMath::Vector class:
    
inline const void	operator=(const Vector &cv);
  

and in the OdinCamera class the Vectors are defined like this:

      
OdinMath::Vector	vecEyePos;
    
So what is up with that? ----- For I have seen the face of evil and it will not soon be forgotten. [edited by - p4n1c on January 13, 2003 7:15:47 PM]
-----For I have seen the face of evil and it will not soon be forgotten.
Teodric
Teodric
Looks to me like the implementation of Vector::operator=() isn''t linked. I''d check if the cpp file containing its implementation is included in the build.
p4n1c
p4n1c
Yup the math file is being included in the build.

This is VS .NET BTW, just in case it matters or not.
-----For I have seen the face of evil and it will not soon be forgotten.
mond
mond
You have a definition, but the linker cannot find your implementation of the assignment operator. You''ll either have to write it or make sure you have it somewhere that the linker can get to it after compilation. Another thing to check is syntax : does the operator= you wrote EXACTLY match the definition in the header. Make sure there are no typos.

greg
p4n1c
p4n1c

  
// In the class that''s in the header file

inline const void operator=(const Vector &cv);

// In the .cpp file where the implementation is

inline const void Vector::operator=(const Vector &cv) {
...
}


And I am using "using namespace OdinMath;" in the source file.
-----For I have seen the face of evil and it will not soon be forgotten.
Dobbs
Dobbs
Are you wrapping the Vector class in the OdinMath namespace?

quote:
Original post by p4n1c
And I am using "using namespace OdinMath;" in the source file.


That''s probably irrelevant since this is a linking problem, not compiling.

This is something of an aside but it''s usually standard to have your assignment operator return a reference to *this (so you can do chained assignments and other tricks).
Also unless I''m forgetting my C++ your function is returning const void??? A const nothing?
p4n1c
p4n1c
Yup, the Vector class is inside the namespace.

The reason it returns nothing is because all it does is take the value on the right hand of the equals and sets an internal array of 'this(the left hand value)' with it's value, and I am also not calling the operator= with a reference. 'this' shouldn't need to be returned.

[edited by - p4n1c on January 13, 2003 7:40:23 PM]
-----For I have seen the face of evil and it will not soon be forgotten.
DerekSaw
DerekSaw

inline const void operator=(const Vector &cv);

What are you suppose to achieve? void don't need to be const.


btw... your problem lies in having inline function in .cpp. Inline should be staying in .h .. or many would say, must be visible to the translation unit (a.k.a. .cpp files).

[edited by - DerekSaw on January 13, 2003 8:03:14 PM]
"after many years of singularity, i'm still searching n the event horizon" o
p4n1c
p4n1c
I'm still trying to get C++ down pat. Thanks for pointing out that the inline functions shouldn't be in the .cpp file.

As for the const void, I've seen static void too. It's just what this math function example code used.

But that didn't fix my problem.

[edited by - p4n1c on January 13, 2003 8:08:38 PM]
-----For I have seen the face of evil and it will not soon be forgotten.
niyaw
niyaw
move function code into the vector class header, or remove all references to ''inline''.
p4n1c
p4n1c
One step ahead of you. I removed all instances of inline from non-header specific functions and it works great.

Thanks all for the ideas and help.
-----For I have seen the face of evil and it will not soon be forgotten.
DerekSaw
DerekSaw
quote:
Original post by p4n1c
As for the const void, I''ve seen static void too. It''s just what this math function example code used.


Are you trying to say you wrote "signed int", "signed long" or "signed short" or even "signed float" just because you saw "unsigned int", "unsigned long" and "unsigned short"??
"after many years of singularity, i'm still searching n the event horizon" o
p4n1c
p4n1c
"Many functions do not examine any values except their arguments, and have no effects except the return value. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared const. For example,

extern const void square ();

says that the hypothetical function square is safe to call fewer times than the program says."

http://www.ictp.trieste.it/texi/gpp/gpp_28.html

There's an example. And I was just following an example. Sorry if I'm not as good in C++ as you are, uber-god. And according to the explaination above, I and the author of the code(Trent Polack, 'mittens' on here) did nothing wrong.

[edited by - p4n1c on January 14, 2003 8:56:09 AM]
-----For I have seen the face of evil and it will not soon be forgotten.
MadKeithV
MadKeithV
Const functions only make sense as const-member functions (functions that do not modify the state of their enclosing class), and in that case, the const goes after the declaration and definition.


  
class SomeClass
{
int theInt_;

public:
SomeClass() {};

int SomeConstFunc() const;
};

int SomeClass::SomeConstFunc() const
{
return theInt_;
}


A const-non-member-function for which any optimisation is valid would just amount to a compile-time constant, since it can''t have any side effects at all to guarantee its const-ness, and would always return the same value.

As an aside, a compiler can hardly do anything with a const declaration to optimise. It''s used mainly to prevent programmer error.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
p4n1c
p4n1c
MadKeith: Could it be because the original declarations were inline and the function bodies in the class? Meaning that I could in fact get rid of all the const references to the functions if I don''t have the function bodies in the class or just move all the function bodies back into the class and put back the inline declaration as the example code has.
-----For I have seen the face of evil and it will not soon be forgotten.
MadKeithV
MadKeithV
The inline definition would still have const at the end of the declaration part. Const before the declaration is always about the return type, as far as I can gather from various books and online resources (and that''s what my gut feeling tells me too).

I just did a small test project, and the compiler (VC.NET) doesn''t barf on the const void Func(), but it seriously dislikes void Func() const, complaining that a nonmember function is not allowed to have modifiers.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
p4n1c
p4n1c
Maybe the MS implementation is broken(heaven forbid Microsoft break something )?
-----For I have seen the face of evil and it will not soon be forgotten.
mond
mond
MadKeith :

Which makes total sense. const on the end of a function tells the compiler that this function will not modify any data. Since the function is not a member of a class (and there is no instance of a class to act on) it would be difficult to say that it modified no data. What data does it have to act on but local and global variables? I suppose you could say that the function didn''t modify globals, but then why would you use a function to modify global data? And why do you have global data in the first place? :^)

On the "const void" issue -- it''s legal but makes no sense. "const void*" on the other hand does make sense and has its uses, albeit small. Saying "const void" on a return type is like passing a long by const reference : "const long& inVar". Sure it''s legal, but your syntax is confusing at first glance. Did you mean to say that the long isn''t modifyable? If so, why not just pass by value (especially since the reference and long sizes on many platforms is the same)? Or did you really mean that you want the long modified in the function, you just forgot to remove the const? Code like this generally gets a verbal beating in code review meetings!

A word of advice : don''t just say that you typed something because you saw it somewhere. If you don''t understand exactly why something is written, you need to find out. You''ll find code samples in many books that no programmer would ever use in the real world due to incorrectness. Just because someone typed it up and published it doesn''t mean it''s right.

greg
MadKeithV
MadKeithV
quote:
Original post by p4n1c
Maybe the MS implementation is broken(heaven forbid Microsoft break something )?


It probably isn''t. If modifiers aren''t allowed on non-member functions, and by extension, const void Func() actually means a function that returns const void (meaningless, really, but valid), that would explain why I couldn''t find any references to const functions other than const _member_ functions. There are no others.
The fact that there''s a compiler error dedicated to the specific error with no references to non-compliance with the standard would suggest so as well.

It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
MadKeithV
MadKeithV
quote:
Original post by mond
What data does it have to act on but local and global variables? I suppose you could say that the function didn''t modify globals, but then why would you use a function to modify global data?



My test did have the function modify global data (the only instance I could think of that the const specifier would have any meaning).

I was pretty certain, but "pretty certain" doesn''t cut it, so I just typed it out, it''s only a few loc anyway. Confirming my suspicion that void const F() or const void F() is no different than const int F() or int const F(), and in the process learning that besides being pretty pointless, a const modifier is in fact illegal on nonmember functions.

So for the record: const void f() is allowed to modify global data all day long, though it would be better to ask yourself why you have global data and a const return type of nothing ;-)
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.

Topic Locked

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

Sign in to reply to this topic.