Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to avoid a class from instantiation?

Answers were Sorted based on User's Feedback



How to avoid a class from instantiation?..

Answer / vinay bondade

Have a Pure Virtual function in the class. This will not
allow to create an object of the class and hence cannot be
instatiated. But its a different thing to inherit the class
and give definition to Pure Virtual function, But the class
alone cannot be instantiated.The class hence,is also called
Abstract Base class.

Is This Answer Correct ?    11 Yes 1 No

How to avoid a class from instantiation?..

Answer / chandrakant

make the class Abstract it will not be instantiated
and the pure virtual function is used to avoid the base call
function to be get called if we make a function as virtual
only a derived class function will get called

Is This Answer Correct ?    3 Yes 0 No

How to avoid a class from instantiation?..

Answer / sanish joseph

Make an abstract class.abstract class cant b intialized.
I think so....

Is This Answer Correct ?    2 Yes 0 No

How to avoid a class from instantiation?..

Answer / achal

Making a constructor private is perfectly legal.
But now u can't create instance of that class.

Is This Answer Correct ?    1 Yes 1 No

How to avoid a class from instantiation?..

Answer / maniac_2004

if you want to construct a class whos constructor is private
then use a static method which constructs the object and
returns the pointer

class A
{
private: A();
public:
static A * createInstance();
};

A* A::getInstance()
{
return new A();
}

main(){ A::createInstance();}

This is similar to the "singleton" pattern...

Is This Answer Correct ?    0 Yes 0 No

How to avoid a class from instantiation?..

Answer / vidushi

Make the class abstract
abstract class abc
{
.....
.....
};

Is This Answer Correct ?    0 Yes 0 No

How to avoid a class from instantiation?..

Answer / ravi

We can aviod a class from instantiation by making all
variants of constructors as private. We can provide user
defined function like create member function under public
scope and call this private construcotrs from this create
function to create an object for that class.

Is This Answer Correct ?    3 Yes 5 No

How to avoid a class from instantiation?..

Answer / rsn

Yes, I agree with Ravi. Classes can be prevented from
instantiating and also from getting inherited using provate
constructors. The initialisation can be done using member
functions in which case it is called "clone" functions(I
hope so, Pls correct me if i'm wrong!).

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C++ General Interview Questions

What is #include iostream in c++?

0 Answers  


What is isdigit c++?

0 Answers  


Do you know the use of vtable?

0 Answers  


What are the advantages of using typedef in a program?

0 Answers  


Which bit wise operator is suitable for checking whether a particular bit is on or off?

0 Answers  


What is the topic of the C++ FAQ list?

1 Answers  


What is c++ in english?

0 Answers  


In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest.

5 Answers   GE,


What are different types of loops in c++?

0 Answers  


Which operations are permitted on pointers?

0 Answers  


Can recursive program be written in C++?

0 Answers  


What are register variables?

0 Answers  


Categories