Can someone explain what am I doing wrong?
Header:
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~
class CMyBase {
private:
CMyBase(const CMyBase& obj); /* Disable copy constuctor */
void operator=(const CMyBase& obj); /* Disable assignment operator
*/
protected:
CMyBase();
public:
virtual ~CMyBase()=0;
};
class CMyChild : public CMyBase {
public:
CMyChild();
void close();
~CMyChild();
private:
int temp;
};
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~
Source
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~
#include "main.h"
CMyChild::CMyCh ild()
: temp (0)
{
}
CMyChild::~CMyC hild() {
close();
}
void CMyChild::close () throw() {
temp = 100;
}
int main(int argc, char **argv)
{
CMyChild child;
child.close();
}
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~
I get to link errors:
main.obj : error LNK2019: unresolved external symbol "protected:
__thiscall CMyBase::CMyBas e(void)" (??0CMyBase@@IA E@XZ) referenced in
function "public: __thiscall CMyChild::CMyCh ild(void)"
(??0CMyChild@@Q AE@XZ)
main.obj : error LNK2019: unresolved external symbol "public: virtual
__thiscall CMyBase::~CMyBa se(void)" (??1CMyBase@@UA E@XZ) referenced in
function "public: virtual __thiscall CMyChild::~CMyC hild(void)"
(??1CMyChild@@U AE@XZ) 6 1728
You're to implement CMyBase::CMyBas e and CMyBase::~CMyBa se.
posted: Can someone explain what am I doing wrong?
Header: ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~ class CMyBase { private: CMyBase(const CMyBase& obj); /* Disable copy constuctor */ void operator=(const CMyBase& obj); /* Disable assignment operator */
Should that not return a reference?
protected: CMyBase();
No point putting that there. Anyway it should be:
CMyBase() {}
public: virtual ~CMyBase()=0;
Not sure if you can have a _pure_ virtual constructor.
-Tomás ro********@gmai l.com wrote: Can someone explain what am I doing wrong?
Header: ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~ class CMyBase { private: CMyBase(const CMyBase& obj); /* Disable copy constuctor */ void operator=(const CMyBase& obj); /* Disable assignment operator */
Usually the assignent op looks like:
T& operator=(const T& rhs)
protected: CMyBase(); public: virtual ~CMyBase()=0;
};
The base constructor and destructor will be called before and after the
derived constructor and destructor, respectively, they must be implemented.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Thank you, that was actually the original code that I once had. However
I thought that since the base class is abstract why would I have to
implement its constructor and destructor? That's strange, however it
seems there is no other way to avoid handmade implementation ro********@gmai l.com wrote: Thank you, that was actually the original code that I once had. However I thought that since the base class is abstract why would I have to implement its constructor and destructor? That's strange, however it seems there is no other way to avoid handmade implementation
An abstract class is a class that has one or more pure virtual
functions. That doesn't mean that it can't do anything at all.
class shape
{
public:
shape(int x0, int y0) : x(x0), y(y0) {}
void draw()
{
do_draw(x, y);
}
virtual ~shape() {}
private:
virtual void do_draw(int, int) = 0;
int x, y;
};
This particular one doesn't do anything interesting in its destructor,
but its constructor is essential.
--
Pete Becker
Roundhouse Consulting, Ltd. ro********@gmai l.com wrote: Thank you, that was actually the original code that I once had. However I thought that since the base class is abstract why would I have to implement its constructor and destructor?
So you can create and destroy objects of that type. You declared the
constructor and destructor and the compiler needs to use them. You must
have a concrete type that derives from the abstract type, right? When
you create and destroy an object of that concrete type, the base object
of the abstract type is created and destroyed as part of the process.
If a class is abstract, that doesn't mean that no objects of that type
can ever be created. You can create as many objects of abstract type as
you wish. But *only* as base objects within objects of a non-abstract
derived type.
Gavin Deane This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hal Vaughan |
last post by:
I'm creating a sequence of JPanels that will each, in turn, be added to
(then removed from) a window (kind of like a wizard). I want these panels
to not only extend the JPanel class, but to implement an interface. I have
the interface defined in a separate class, like this:
public interface IPanel {
boolean onNext();
String nextPanel();
boolean hasCancel();
|
by: Macka |
last post by:
A few pieces of information first:
* I have a class called Folder which represents a row of data in a
database table. The data access side of things is not an issue.
* The table has a parent column which references itself (ie. Adjacency
or parent/child model)
* I have a public property called 'Parent' which returns me a new
reference to a Folder instance containing the data of the parent row.
|
by: Dan Sikorsky |
last post by:
If we were to define all abstract methods in an abstract class, thereby
making that class non-abstract, and then override the heretofore 'abstract'
methods in a derived class, wouldn't that remove the need to have abstract
class types in C#?
Derived classes from abstract base classes must overrided the abstract
method defininition anyway, so why not just provide a complete definition
for the abstract method when defining the containing...
|
by: yohaas |
last post by:
I'm trying to do something, not sure if it's possible or even if it
makes sense, but I figured I'd throw it out there.
I have a class OrderSummary that contains information about an order. I
then have two classes that inherit OrderSummary; K_OrderSummary and
M_OrderSummary which are specific types of orders. I will not know what
type of order it is until runtime so I want to create an object of type
OrderSummary. I only want to have to...
|
by: Peter Oliphant |
last post by:
Is there a way of defining a method in a base class such that derived
classes will call their own version, EVEN if the derived instance is
referred to by a pointer to the base class? Note that the base class method
is not to be abstract, and will be called if the instance was created as a
'generic' base class instance.
It's sort of like I want the method to be abstract to children, but concrete
at the base level. That way I can refer to...
| |
by: zouyongbin |
last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this
should not appear in a header file:
int ix;
The inclusion of any of these definitions in two or more files of the
same program will result in a linker error complaining about multiple
definitions. So this kind of definition should be avoided as much as
possible. But as we know, the definition of a class is always in a
header file. And we can use "#ifndef" to eliminate...
|
by: Bart Simpson |
last post by:
I m getting a ton of linkage errors (unresolved externals) when using an
abstract base class. My classes look something like this:
class BaseObject
{
//pure virtuals
virtual void foo() = 0;
virtual int foobar(int, int, double) = 0 ;
virtual void grok();
|
by: Flomo Togba Kwele |
last post by:
I am having trouble with the following design. I want an object containing a Parent object and a
List of its Child objects. The Child object is abstract, so the List must contain concrete objects
derived from it.
When I instantiate the ParentChild object and add Child-derived objects to the List, I will be able
to add any object derived from Child. However, I want the List to contain only a single type
derived from Child, and I want...
|
by: Daniel Smedegaard Buus |
last post by:
Hello there :)
I'm trying to implement some basic DRY MVC-like functionality as a
basis to work on. Specifically, I'd like to create a base abstract
model class with basic read, write, delete and update database
functionality, that I can use for all models in my code. I'd pretty
much like it to go like this (if there are a few errors, you'll have
to forgive me, I just woke up and I don't have the code on me, getting
ready to go to work,...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |