i just started learning to prog in c++, im using netbeans.
i tryed to use a class and i keep getting this error. what am i doing wrong ?
-----------------------------
| CODE |
class test { public: int funtime();
private: int time; };
int test::funtime() { return time; } |
---------------------------
when i try to build
i keep getting the error
/home/leandro/netbeans/testjes/testklasse.cc:13: multiple definition of `test::funtime()'
thnx in advance
| QUOTE (akira300 @ Feb 9 2007, 08:22 AM) |
i just started learning to prog in c++, im using netbeans. i tryed to use a class and i keep getting this error. what am i doing wrong ? -----------------------------
| CODE | class test { public: int funtime();
private: int time; };
int test::funtime() { return time; } |
--------------------------- when i try to build i keep getting the error /home/leandro/netbeans/testjes/testklasse.cc:13: multiple definition of `test::funtime()'
thnx in advance
|
If you have the function defintion in the header file (.h) then it will be defined in each source file (.cpp). Thus the linker will see multiple definitions.
There are two solutions:
1) Move the function definition:
| CODE |
int test::funtime() { return time; } |
into a source file.
2) Declare the defintion inline.
| CODE |
inline int test::funtime() { return time; } |
mmm ill explain better
-------------------------
overvieuw

main

class rubbish that gives the error

my output