473,772 Members | 3,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ABCs (abstract base classes) and linkage problems

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();
virtual int doit();
}
class MyClass : public BaseObject
{
//pure virtuals are implemented
void foo() {...}
int foobar(int a, int b, double c){return 42;}

//these are not implemented .. and not called in code
//virtual void grok();
//virtual int doit();

}
Linkage errors (unresolved externals):

BaseObject::Bas eObject(void)
void grok()
int doit();
which leads to my questions:

i). Why is the linker looking for the constructor of the ABC BaseObject?
ii). Do I need to implement the constructor of BaseObject ? (this goes
against my understanding of most languages definition of an interface)
iii).Why is the linker looking to resolve the two (non pure) virtuals in
the interface - I dont use it any where in the code - and it is only
there for "future comapatability"

What am I doing wrong ?


Jun 3 '07 #1
4 1660
On Jun 2, 8:43 pm, Bart Simpson <123evergr...@t errace.comwrote :
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();
virtual int doit();

}
; // missing semicolon
>
class MyClass : public BaseObject
{
//pure virtuals are implemented
void foo() {...}
int foobar(int a, int b, double c){return 42;}

//these are not implemented .. and not called in code
//virtual void grok();
//virtual int doit();

}
; // missing semicolon
>
Linkage errors (unresolved externals):

BaseObject::Bas eObject(void)
void grok()
int doit();

which leads to my questions:

i). Why is the linker looking for the constructor of the ABC BaseObject?
Because even though the base object's ctor is not declared by you, the
compiler will generate one that is non-virtual and implemented
(assuming you declared your class appropriately).
ii). Do I need to implement the constructor of BaseObject ? (this goes
against my understanding of most languages definition of an interface)
No, that depends on what you do with that class. First, you must
declare a class. You didn't.
class Base { }; // is a class
class Base { } // is not
iii).Why is the linker looking to resolve the two (non pure) virtuals in
the interface - I dont use it any where in the code - and it is only
there for "future comapatability"

What am I doing wrong ?


Jun 3 '07 #2


Salt_Peter wrote:

<snip>
>
; // missing semicolon

>>Linkage errors (unresolved externals):

BaseObject::B aseObject(void)
void grok()
int doit();
</snip>

If you had bothered to read the title of this post, you would have
realized that these were linkage (not compiler) errors - hence your
nitpicking over missing semicolons, totally misses the point, and does
not add any useful information. The code snipet I posted was a summary
to give a gist/overview of the object heirarchy that illustrated what I
was contending with .... in any case, I managed to resolve the issue
myself (hence the deletion of the post)
Jun 3 '07 #3
On Jun 2, 10:21 pm, Bart Simpson <123evergr...@t errace.comwrote :
Salt_Peter wrote:

<snip>
; // missing semicolon
>Linkage errors (unresolved externals):
>BaseObject::Ba seObject(void)
void grok()
int doit();

</snip>

If you had bothered to read the title of this post, you would have
realized that these were linkage (not compiler) errors - hence your
nitpicking over missing semicolons, totally misses the point, and does
not add any useful information. The code snipet I posted was a summary
to give a gist/overview of the object heirarchy that illustrated what I
was contending with .... in any case, I managed to resolve the issue
myself (hence the deletion of the post)
Please read the FAQ, something that is expected of you _before_
posting here, partcicularly this section:
http://www.parashift.com/c++-faq-lite/how-to-post.html
[5.8] How do I post a question about code that doesn't work correctly?

Jun 3 '07 #4
On Jun 3, 2:43 am, Bart Simpson <123evergr...@t errace.comwrote :
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();
virtual int doit();
}
class MyClass : public BaseObject
{
//pure virtuals are implemented
void foo() {...}
int foobar(int a, int b, double c){return 42;}
//these are not implemented .. and not called in code
//virtual void grok();
//virtual int doit();
}
Linkage errors (unresolved externals):
BaseObject::Bas eObject(void)
void grok()
int doit();
which leads to my questions:
i). Why is the linker looking for the constructor of the ABC BaseObject?
Is it declared in the base class. The constructor of MyClass
will implicitly call it. If you don't declare it in the base
class, the compiler automatically generates one, which is
inline, so you shouldn't get any linker errors because of it.
If you do declare it, however, it will be called, and so you
must have an implementation.
ii). Do I need to implement the constructor of BaseObject ? (this goes
against my understanding of most languages definition of an interface)
If you declare it, you have to define it. If you're really
defining an interface, typically, you don't declare it, and
there's no problem.
iii).Why is the linker looking to resolve the two (non pure) virtuals in
the interface - I dont use it any where in the code - and it is only
there for "future comapatability"
A function which is declared virtual (but not pure virtual) is
"by definition" used as soon as you instantiate the class, or an
class derived from it. So you need a definition. (The reason
for this is that the compiler will typically want to put the
address of the function in the vtable.)

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 3 '07 #5

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

Similar topics

9
2304
by: Christian Christmann | last post by:
Hi, I've a class Handler which contains a STL list std::list<Abstract*> mAbstract; which is storing elements of the abstract class Abstract. Further this class has a getElement function to return a specific element of the list. The abstract class Abstract has some virtual pure function which are used with all concrete classes derived from it.
3
1528
by: Sunny | last post by:
Hi again, in the past I have posted here a problem with static methods and abstract classes, and Jon Skeet and Richard Lowe have helped me to clarify the things. But now I have found another problem (I have posted similar thing in vs.ide newsgroup, but I do not know if this is and IDE or C# problem, so I post it here also).
3
4307
by: Magne Ryholt | last post by:
I have a base class and a chain of derived classes. The base and its derived classes are all abstract except the last in chain (a concrete class). I want to provide some functionalities in the base class by defining a member as e.g. "protected virtual MyReturnClass MyMethod(){...}" The base classes, including the last (concrete class) adds on this functionality by defining members as e.g. "protected override MyReturnClass MyMethod(){......
9
5200
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
9
5506
by: silversurfer2025 | last post by:
Hello everyone, I am currently having problems with a C++ abstract class. I have a class FrameWork.h which defines some methods (of which some are abstract, i.e. virtual void method() = 0). In FrameWork.cpp I define some of the methods while I naturally leave the abstract methods undefined. Now I wrote a class FrameWork_GUI.h which inherits from the abstract FrameWork class and implements the missing (so far abstract) methods....
3
2170
by: Ernesto Bascón | last post by:
Hi everybody: I have two questions: 1. I'm using opaque pointers in my classes to hide their data structures; there is a way to use opaque pointers in template classes; since the implementation and the declaration of the template class is in the same file, the use of opaque pointers does not make sense, but... what about implementation hiding for libraries? how can I make sure that the new versions of my libraries have binary...
4
1442
by: Paulo Matos | last post by:
Hi all, C++ FAQ Lite points you out to ABCs to define interfaces in C++, however, in a well-defined big system which may consist of a huge number of interfaces, the use of ABCs may incur in a very heave performance penalty due to virtual functions, right? Are there any alternatives to define "interfaces" in C++ without the use of ABCs?
4
1872
by: Eric | last post by:
I was wondering what people thought about the information found at: http://g.oswego.edu/dl/mood/C++AsIDL.html Specifically, I am interested in the following recommendation: ---- Since interface classes cannot be directly instantiated, yet serve as virtual base classes for implementations, the constructors should take no arguments and should be listed as protected. Also, for similar
0
2835
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
0
9620
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
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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
8934
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
7460
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
6715
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.