473,605 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2184
On Jul 5, 1:51 pm, "qazmlp1...@red iffmail.com"
<qazmlp1...@red iffmail.comwrot e:
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********@redi ffmail.com <qa********@red iffmail.comwrot e
in <11************ *********@e16g2 000pri.googlegr oups.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
3947
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 update database or object is read-only". This is a workstation machine, not connected to any other computer, and I login to the PC using an administrator account. I already check the .MDB file is NOT read-only. But, I do not see the .LDB file....
2
411
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
1948
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 implemented. An error "Cannot be converted into parameter type System.Data.DataTable". Please help to provide me a solution for my problem. Thank you for your kind support.
2
4096
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 definition: Column | Type | Modifiers -------------------+------------------------+---------------------------------------------------- self | datagraph."GOLink" | not null default
0
2053
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 tried a few things that I found in postings, but I'm not getting anywhere. Please advise on what I can do. '------------------------------------------------------------ ' mcr_Export_Test '
1
6103
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 <?php phpinfo(); ?> command which prints out the current settings of the php install. I then installed mySQL complete setup (V5) and ran the server instance
5
3664
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 determine the rank of a character but I keep getting errors. I want to "redefine" some attributes from the base class so I can use them to help determine the rank. However, I get the error that my base class doesn't have the dictionary that...
2
4062
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 returning the error "cannot create ActiveX component" and then the program crashes. Any help is much appreciated. Thank you. Larry
14
3821
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, EventArgs e) { txt1 = textBox1.Text; txt2 = textBox2.Text;
0
8007
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8290
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6749
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.