Costructorul este declarat intr-un fisier header.
test4.h
#ifndef TEST4_H_INCLUDED
#define TEST4_H_INCLUDED
class TestClass
{
private:
TestClass();
public:
static TestClass* getTestClass();
};
#endif // TEST4_H_INCLUDED
main.cpp
#include <iostream>
#include "test4.h"
using namespace std;
int main()
{
TestClass *ptr = TestClass::getTestClass();
delete ptr;
return 0;
}
test4.cpp
#include <iostream>
#include "test4.h"
using namespace std;
TestClass::TestClass()
{
cout << "\n Apel constructor!" << endl;
}
TestClass* getTestClass()
{
return new TestClass();
}