hi guys i am having a problem with using my class in c++.
i have written my class code as a header file and ihave included it in the source code
i get the compiler error:
1>extended.obj : error LNK2019: unresolved external symbol "class Token __cdecl get_token(void)" (?get_token@@YA?AVToken@@XZ) referenced in function _main
1>C:\Users\Minh-Long\documents\visual studio 2010\Projects\calculator (console type)\Debug\calculator (console type).exe : fatal error LNK1120: 1 unresolved externals
how to use class in c++
Page 1 of 13 Replies - 467 Views - Last Post: 09 July 2010 - 06:04 PM
Replies To: how to use class in c++
#2
Re: how to use class in c++
Posted 09 July 2010 - 12:53 AM
The Compiler can't find the body of get_token function. It is prototyped somewhere, but it is not implemented.
#3
Re: how to use class in c++
Posted 09 July 2010 - 05:42 PM
Usually, you will see classes defined similarly:
In C++, it is good practice to encapsulate the details of things. However, the implementation of the functions are not implemented yet. Failing to implement a function that is being used will result to an error.
Of course, you could always include the implementation inside the class definition:
The reason you don't see this done much in C++ is because it does not hide the implementation. Most of the time, people using classes written by someone else does not care about the implementation of the methods. They just care what it does, but not how it does it.
class foo
{
public:
foo();
~foo();
void method();
private:
int member;
};
In C++, it is good practice to encapsulate the details of things. However, the implementation of the functions are not implemented yet. Failing to implement a function that is being used will result to an error.
foo::foo():
member( 0 )
{
// Do something.
}
foo::~foo()
{
// Do something.
}
void foo::method()
{
// do something.
}
Of course, you could always include the implementation inside the class definition:
class foo
{
public:
foo()
{
// do something.
}
~foo()
{
// do something.
}
void method()
{
// do something.
}
private:
int member;
};
The reason you don't see this done much in C++ is because it does not hide the implementation. Most of the time, people using classes written by someone else does not care about the implementation of the methods. They just care what it does, but not how it does it.
This post has been edited by sparkart: 09 July 2010 - 05:46 PM
#4
Re: how to use class in c++
Posted 09 July 2010 - 06:04 PM
Especially since all you will usually be provided in the header and accompanying libraries, object files, or whatever.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|