473,394 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 2169
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 update the database, it gave me the error "cannot...
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 ICustomTypeDescriptor { private: ...
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 System.Data.DataTable as input parameter is...
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 table in my database. Here is the tables...
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: "Cannot update. Database or object is read-only." I've...
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 responce from php(V5 - manual install) though the ...
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 trying to build a subclass that has methods to...
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 of code wordDoc = GetObject("sheet.doc") keeps...
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 private void button1_Click(object sender,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.