i'll just tell you in short how my Problem looks like: I should implement a New Class in a SourceCode i didnt write myself. The source code is extremely sized (i think approx >100.000 Lines of Code), so i dont want to change too much in it in order to get my Implementation done.
MY problem looks simplicified like that: Starting from 3 classes and my new class the pseudo-code looks like that:
So, i need Parameters from 3 different classes to insert in my NewClass. The 3 Classes dont know anyting about each other. So, i need to implement a Class-Instance from Type NewClass which is known by the other 3 Classes. I did solve it in this way:
i just wrote a headerfile with a class-instance which is getting included by the other 3 Classes. So they all know the same Instance and writing their Parameters into it.
Is this a decent solution or could it happen to get bugs/ logical mistakes with it?
> i just wrote a headerfile with a class-instance which is getting included by the other 3 Classes.
> So they all know the same Instance and writing their Parameters into it.
No, they are not. You have one instance of NewClass per translation unit.
If the same single instance is to be used everywhere:
1 2 3 4
//ClassInstance.h
class NewClass ;
extern NewClass ClassInstance ;
So , i tried to implement the singelton-class via a pattern i found on wikibooks.
it looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class N
{
public:
static N& instance()
{
static N _instance;
return _instance;
}
~N() {};
void xyz();
private:
N() {};
N( const N& );
N & operator = (const N &);
};
so, this is what i write in the header-file right? when i try to define my class-functions in the .cpp/ .cc file i get errors when i start to declare a standard-constructor. someone knows how to write the methods in the .cpp file? do i even need a constructor, since the compiler doesnt mock when i compile wihtout constructor.