private-constructor

How to instantiate an object with a private constructor in C#?

I definitely remember seeing somewhere an example of doing so using reflection or something. It was something that had to do with SqlParameterCollection which is not creatable by a user (if I'm not mistaken). Unfortunately cannot find it any longer. Can anyone please share this trick here? Not that I consider it a valid approach in deve...

Impossible to inherit from this object?

Following up on this question, people have suggested I go with "option 3" which might look like this: class b2Body { private: b2Body() {} friend class b2World; }; class Body : public b2Body { private: Body() {} friend class World; }; class b2World { public: b2Body *CreateBody() { return new b2Body; } }; class World : public b...

c++: Private constructor means no definition of that classes objects inside headers?

Yet another question, go me!... Anyway, I have 2 classes with private constructors and static functions to return an instance of that class. Everything was fine, I have a main.cpp file where I managed to get hold of my gameState object pointer, by doing: gameState *state = gameState::Instance(); But now I seem to have a problem. For t...

Preventing call of a private constructor from within the class in java

Hi We can restrict the creation of object of a class by making its constructor private. But this constructor could still be called from within the class. Is there any way to prevent this in Java? Thanks. ...

How to use a object whose copy constructor and copy assignment is private?

In reading TCPL, I got a problem, as the title refered, and then 'private' class is: class Unique_handle { private: Unique_handle& operator=(const Unique_handle &rhs); Unique_handle(const Unique_handle &rhs); public: //... }; the using code is: struct Y { //... Unique_handle obj; }; and I want to execute such op...

How to use objects that got the private copy-constructor and assignment-constructor?

Possible Duplicate: How to use a object whose copy constructor and copy assignment is private? In reading TCPL, I got a problem, as the title refered, and then 'private' class is: class Unique_handle { private: Unique_handle& operator=(const Unique_handle &rhs); Unique_handle(const Unique_handle &rhs); public:...

In C++, can I represent a class type as a variable?

I would like to call a static method from a class that I'll determine at run-time, but which I know subclasses a given class. So let's say I have these classes class super { public: super(); static super *loadMe (ifstream &is); } class subA : public super { public: subA(); static super *loadMe (ifstream &is); } c...