472,342 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

error: "Cannot create a value of the abstract class base"

class base
{
public:
base()
{

}
base(int number)
{
priNumber = number ;
}

void pubFunc1()
{
// use 'priNumber' and do some tasks
}

void pubFunc2()
{
// use 'priNumber' and do some tasks
}

virtual void pubFunc3() = 0 ;

private:
int priNumber ;
} ;

class derived_one : public base
{
public:
derived_one()
{
base( 1 ) ;
}

void pubFunc3()
{
//
}

} ;

class derived_two : public base
{
public:
derived_two()
{
base( 2 ) ;
}

void pubFunc3()
{
//
}
};

I'm getting the compilation error: "Cannot create a value of the
abstract class base".

Only the objects of the derived classes make sense. Also, there is a
common implementation required for the pubFunc1 & pubFunc2 based on
the parameter 'priNumber' value. What is the other way of passing this
parameter to the base class function?

Jul 5 '07 #1
2 2032
On Jul 5, 1:51 pm, "qazmlp1...@rediffmail.com"
<qazmlp1...@rediffmail.comwrote:
class base
{
public:
base()
{

}
base(int number)
{
priNumber = number ;
}

void pubFunc1()
{
// use 'priNumber' and do some tasks
}

void pubFunc2()
{
// use 'priNumber' and do some tasks
}

virtual void pubFunc3() = 0 ;

private:
int priNumber ;

} ;

class derived_one : public base
{
public:
derived_one()
{
base( 1 ) ;
}
Here, you are *creating* a new object of base class. That is not
allowed since base class is abstract.

But I guess what you want is not a *new* object of base class, but
initializing the base component of derived_one using the appropriate
value. Use member initialization list.

derived_one() : base(1) { }

>
void pubFunc3()
{
//
}

} ;

class derived_two : public base
{
public:
derived_two()
{
base( 2 ) ;
}
Same. Use
derived_two() : base(2) { }
-Neelesh

Jul 5 '07 #2

qa********@rediffmail.com <qa********@rediffmail.comwrote
in <11*********************@e16g2000pri.googlegroups. com>:
class base
{
public:
base()
{

}
virtual ~base () {}
base(int number)
{
priNumber = number ;
}
[...]
virtual void pubFunc3() = 0 ;

private:
int priNumber ;
} ;

class derived_one : public base
{
public:
derived_one()
{
base( 1 ) ;
}
[...]
I'm getting the compilation error: "Cannot create a value
of the abstract class base".
Try:

derived_one () : base (1)
{
}

--
Pavel Lepin
Jul 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to...
2
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public...
0
by: Chun | last post by:
Dear All I am now facing a problem when i try to pass a custom datatable datatype value to a remote server. In the remote server, a method with...
2
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific...
0
by: mvdkwong | last post by:
I am trying to run a macro that will export a table into a fixed length file (see below). However, when I run it, I get the following error:...
1
by: marknewbery | last post by:
Hi, I have been trying to get a php, mySQL install to work and talk together on Windows XP SP2 with IIS. So far I installed and received a...
5
by: crystalattice | last post by:
I've finally figured out the basics of OOP; I've created a basic character creation class for my game and it works reasonably well. Now that I'm ...
2
by: ironmanlarry | last post by:
Hi, I'm trying to do a mail merge from Excel to Word (programatically) and I'm having some trouble creating the Word Document Object. This line...
14
by: sarabonn | last post by:
hallo Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.