![]() |
|
#1
|
|||
|
|||
error related to static member functions and varaiblesCPP / C++ / C Code:
error LNK2001: unresolved external symbol "private: static int static_type::i" (?i@static_type@@0HA) Debug/a.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. what should i do, usually when i get this type of error i just close Vc++ and then re-enter and compile the program again and ... thats about it ! i don't get the error again, but with this one ... doesn't work. need ur help fast. thanks kai85. |
|
#2
|
||||
|
||||
|
You need to "declare" your static variables in exactly one place before using your class:
CPP / C++ / C Code:
You can initialise it to a value in the same place if you need to. Quote:
You should send this to Microsoft! I wonder what they would say to that complaint! Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
|
Quote:
but why? why do i need to declare istatic varables in exactly one place before i use them ? and by this exactly one place do u mean before the main function? thanks kai85. |
|
#4
|
||||
|
||||
|
Quote:
Because if you declare it more than one place you will anger the little imps that live in your compiler and they will refuse to work. They will claim confusion and direct you to their union rep. Well, maybe not exactly but it paints a pretty picture, don't it? Using the code example you can see how Luci seperated your declaration of your static integer in the definition of your class: CPP / C++ / C Code:
from your definition in the implementation of the class member variable. CPP / C++ / C Code:
You could do a number of things.
For the first one it would look like: CPP / C++ / C Code:
The second one also uses inclusion guards on the header file as good practice. CPP / C++ / C Code:
CPP / C++ / C Code:
Finally the third example from my list which is good when things start getting larger and more complex. CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The