Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

abstract classes

Status
Not open for further replies.

joeGrammar

Programmer
Jun 4, 2001
162
CA
A question for all you pure virtual function experts out there

Say I have created a dll and I wanted to define functions within a class in a console application accessing this dll... then I would have to make the functions pure virtual and in turn make the class abstract.


When defining these functions in the console application I would just write:

classname::function(param)
{

body

}

and this should work. What if there are functions within the class that aren't pure virtual and need to be fed private member variables fed to the constructor(ie accessor function)

How can we pass values to the constructor when we can't instantiate the darn class? (THIS IS NOT MY CODE :) )

Any help would be appreciated



 
I am a bit confused by your post.

I can however explain pure virtual classes


class pv // pure virtual class

class ih: public pv // class ih inherits from pv

In class ih you define the pure virtual functions and when instantiating a class you dont instantiate one of pv you instantiate one of ih. Most likely the constructor for pv is protected so in the constructor for ih you will call the protected constructor of pv. It has been a while since I have used a pure virtual class but I am not sure if the constructor can be pure virtual. If the constructor is NOT pure virtual then this constructor could have some initialization of its own and you should call it from ih. If it is, then do all your initialization of protected data members in the constructor for ih.

I hope this clarified things a bit.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top