Hi)
Can someone help me with one problem?)
In my project there are two files: cT.h (file header of some class cT) and main.cpp; The code of these files shown below;
cT.h
1 2 3 4 5 6
class cT
{
public:
cT();
~cT();
};
main.cpp
1 2 3 4 5 6 7 8 9
#include "cT.h"
int main()
{
cT *_a; //Why compiler tell that everything is OK? But we don't have a realization of constructor and destructor!
return 0;
}
In my opinion the compiler must tell that it can not find the realization of cT() and ~cT(); Please, explain me this.
That is because you just have a pointer to cT, not an actual instance of cT.
Neither the constructor nor the destructor is ever called, so the linker has no reason to complain.
sorry my bad, but wouldn't it be ok anyway? I mean its not like the constructor is private or anything??? sorry I'm new don't fully understand instances of classes yet and all that jazz...
never mind I got it now its because he only declared the constructor etc yet not defined them?
I usually declare & define my constructors in the header file so I didn't notice.