Re: constructor
nik wrote:
plz tell me if we declare constructor as private member of class and
want to create obj of that class. Is it possible? the way in which the
situation is solved
There are several ways. You might have a friend who could create an
instance because it has access to the private parts, or there might be
a public function that creates instance(s) of the class:
class A
{
private:
A() {}
public:
static std::auto_ptr<A> Create()
{
return std::auto_ptr<A>( new A );
}
};
The constructor might also be private if you shouldn't use that
constructor or create instances of the class at all, e.g., if it's a
template typedef equivalent:
template<class T, class U>
struct B
{
typedef T Type1;
typedef U Type2;
};
template<class U>
struct BWithInt
{
typedef B<int,U> Type;
private:
BWithInt(); // Private and undefined on purpose
};
BWithInt<float> someB; // Compile-time error: private c-tor
BWithInt<float>::type someOtherB; // Ok
Cheers! --M