newbie problem
can someone say what''s wrong with my code.. when i compile it i get linker error message "main.obj : error LNK2001: unresolved external symbol "class TEST test" (?test@@3VTEST@@A)".
-------main.cpp
#include
#include "test.h"
int main(int argvc, char* argv[])
{
printf("%i", test.t());
return 0;
}
-------test.h
#ifndef TEST_H
#define TEST_H
class TEST
{
public:
int t();
};
extern TEST test; // this causes an error.. why?
#endif TEST_H
-------test.cpp
#include "test.h"
int TEST::t()
{
return 54; // amazing function? =)
}
ok... so what should i do different? and as you can see, i''m new at c++.. =)
the problem is that you only declare "test" by using the extern keyword.
if you use extern, you must define the variable somewhere else.
either you put "TEST test;" in front of your main.cpp file to define test as a global variable, or you just ditch your extern keyword.
then the linker shouldn''t complain any more
ridcully
if you use extern, you must define the variable somewhere else.
either you put "TEST test;" in front of your main.cpp file to define test as a global variable, or you just ditch your extern keyword.
then the linker shouldn''t complain any more
ridcully
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement