inline constructors

A

aryan

Hello,

The following code throws "undefined reference to `Buster::Buster()'"
unless I remove inline keyword. Could someone please explain why?

//************************
// In file buster.h
//************************
class Buster {
private:
static int instanceCount;
public:

Buster();

virtual
~Buster();

static
int
getInstanceCount();

};

//**************************
//In file buster.cpp
//**************************
int
Buster::instanceCount = 0;

inline
Buster::Buster() {
instanceCount++;
}

int
Buster::getInstanceCount() {
return instanceCount;
}

inline
Buster::~Buster() {
instanceCount--;
}
///////////////////////////////////////

Thanks.
 
A

aryan

So moving the inline definitions to the header file should solve the
problem, right?

Its strange the inline definition of destructor in .cpp file did not
cause any error. I guess this is because the destructor cannot be
called explicitly.
 
J

Jonathan Lee

So moving the inline definitions to the header file should solve the
problem, right?

Or dropping the inline keyword.
Its strange the inline definition of destructor in .cpp file did not
cause any error. I guess this is because the destructor cannot be
called explicitly.

My guess would be that since the constructor couldn't be
found (and thus the type couldn't be instantiated),
it never even looked for the destructor.

--Jonathan
 
A

aryan

My guess would be that since the constructor couldn't be
found (and thus the type couldn't be instantiated),
it never even looked for the destructor.

I only corrected the constructor. It compiles without warnings/errors.

-
Kiran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top