I am running a C++ program which uses a class from another .cpp file. The class only has a constructor. It works when I test it separately. The main program compiles,but when I run it, I have a bug in the constructor. Any one can think of any situation that could happen? Thanks.
I guess I just run the code in terminal, and it is fine. But when I try to build a project in eclipse, it shows following code has multiple definition error:
class model
{
public:
int textures [];
float vertices[][3];
float triangles[][13];
public:
model(const char*); // constructor
};
model::model(const char* filename)
{
error message is: multiple definition of `model::model(char const*)’
any idea?
You need to split your code into a .h (header) and a.cpp (implementation) file and put:
in the latter. Or, rewrite your class so the definition of the constructor (and any other member functions) is inside the class in the header file: