473,770 Members | 3,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Inheritance

Hi,

I've been developing this API, but now I get stuck in a compiling error
and I'm out of ideas. Some comments are welcome.

The hierarchy is bases in three classes, and I will explain it bellow in
detail.

The three classes are:
1 - IFolderManager -> abstract base class
2 - FolderManagerCo mmon : public IFolderManager
3 - FolderManager : public FolderManagerCo mmon

The properties of this relation are:

1 - IFolderManager has only abstract methods and no attributes.

2 - IFolderManagerC ommon implements a small set of methods from the base
class.
3 - IFolderManagerC ommon declares and implements some protected methods,
and as some private attributes.
4 - IFolderManagerC ommon has no constructors, since it is also an
abstract class (doesn't implement all the methods from the base class).

5 - FolderManager implements all the methods from the base class that
are not implemented by FolderManagerCo mmon.

6 - All the three classes have virtual destructors.
7 - All methods are virtual.
8 - Only FolderManager has constructors.

From this description we see that the union of FolderManagerCo mmon and
FolderManager implement all the methods declared by the interface (base
class).

The problem is that when I compile the code I get the following error:
.../src/common/FolderManagerCo mmon.h:7: error: candidates are:
FolderManagerCo mmon::FolderMan agerCommon(cons t FolderManagerCo mmon&)

This error points to the constructor of FolderManager, in
FolderManager.c xx. And I have no ideia of what is going on.

I've tried to explain to resume the error, so that there was no need to
look at the code. But I will place the code here also, in case I
couldn't explain myself:
--------------------------------------------------------------
IFolderManager. h
--------------------------------------------------------------
#ifndef IFOLDERMANAGER_ H
#define IFOLDERMANAGER_ H
#include "ITableManager. h"
#include <vector>
#include <string>
using namespace std;

/** @interface
* @stereotype base_class */
class IFolderManager {

public:
virtual IFolderManager* createFolder(co nst string& folderName,
const string& folderAttribute s,
const string& folderDescripti on) const
throw (TIDB_Exception ) =0;

virtual ITableManager* createTable(con st string& tableName,
ICondDBTable& table,
const string& tableAttributes ,
const string& tableDescriptio n) const
throw(TIDB_Exce ption)=0;

virtual void deleteFolder(co nst string& folderName) const
throw (TIDB_Exception ) = 0;

virtual void deleteTable(con st string& tableName) const
throw (TIDB_Exception ) = 0;

virtual IFolderManager* getFolderManage r(const string& folderName)
const
throw(TIDB_Exce ption)= 0;

virtual vector < IFolderManager >* getFolderManage rs() const
throw(TIDB_Exce ption) = 0;

virtual ITableManager* getTableManager (const string& tableName) const
throw(TIDB_Exce ption) = 0;

virtual vector < ITableManager >* getTableManager s() const
throw(TIDB_Exce ption)= 0;

virtual const string& getDescription( ) const =0;

virtual const string& getPath() const =0;

virtual const string& getVersion() const=0;

virtual ~IFolderManager () {} //dummy destructor
};
#endif //IFOLDERMANAGER_ H
--------------------------------------------------------------
IFolderManagerC ommon.h
--------------------------------------------------------------
#ifndef FOLDERMANAGERCO MMON_H
#define FOLDERMANAGERCO MMON_H

#include "IFolderManager .h"
#include "../common/IDatabase.h"

class FolderManagerCo mmon : public IFolderManager {
public:
virtual const string& getDescription( ) const;

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerC ommon();

protected:
virtual const IDatabase& getDatabase() const;

private:
string path;
string version;
string description;
IDatabase& database;
};

#endif // FOLDERCOMMON_H
--------------------------------------------------------------
FolderManager.h
--------------------------------------------------------------
#ifndef FOLDERMANAGER_H
#define FOLDERMANAGER_H
#include "../common/FolderManagerCo mmon.h"

/**
* @stereotype Oracle
*/
class FolderManager : public FolderManagerCo mmon {

public:
FolderManager(c onst string& path, const IDatabase& database);

virtual IFolderManager* createFolder(co nst string& folderName,
const string& folderAttribute s,
const string& folderDescripti on) const
throw (TIDB_Exception );

virtual ITableManager* createTable(con st string& tableName,
ICondDBTable& table,
const string& tableAttributes ,
const string& tableDescriptio n) const
throw (TIDB_Exception );

virtual void deleteFolder(co nst string& folderName) const
throw (TIDB_Exception );

virtual void deleteTable(con st string& tableName) const
throw (TIDB_Exception );

virtual IFolderManager* getFolderManage r(const string& folderName)
const
throw (TIDB_Exception );

virtual vector < IFolderManager >* getFolderManage rs() const
throw (TIDB_Exception );

virtual ITableManager* getTableManager (const string& tableName) const
throw (TIDB_Exception );

virtual vector < ITableManager >* getTableManager s() const
throw (TIDB_Exception );

virtual ~FolderManager( );

private:

/** @link dependency */
/*# P_Folder lnkFolder; */

/** @link dependency */
/*# P_Table lnkTable; */
};
#endif //FOLDERMANAGER_H

Jul 22 '05 #1
4 1401
Gama Franco wrote:
....

The problem is that when I compile the code I get the following error:
../src/common/FolderManagerCo mmon.h:7: error: candidates are:
FolderManagerCo mmon::FolderMan agerCommon(cons t FolderManagerCo mmon&)

This error points to the constructor of FolderManager, in
FolderManager.c xx. And I have no ideia of what is going on.
It seems you have missed putting FolderManager.c xx in your code snippet.
I have not been able to reproduce the error you describe with the code
you have posted.

Please post a complete, compileable snippet of code that demonstrates
the problem you describe.

Anyhow, you do mention "error points to the constructor of
FolderManager". FolderManager has no declared constructor so it's using
the default constructor generated by the compiler. It seems you are
defining a new one in the .cxx file which is probably an error.

I've tried to explain to resume the error, so that there was no need to
look at the code. But I will place the code here also, in case I
couldn't explain myself:


.... the code below, which does not have any errors under gcc 3.4, was
taken from your original post.

#include <vector>
#include <string>
using namespace std;

struct TIDB_Exception {};
struct ITableManager {};
struct ICondDBTable {};
struct IDatabase {};

/** @interface
* @stereotype base_class */
class IFolderManager {

public:
virtual IFolderManager* createFolder(co nst string& folderName,
const string& folderAttribute s,
const string& folderDescripti on) const
throw (TIDB_Exception ) =0;

virtual ITableManager* createTable(con st string& tableName,
ICondDBTable& table,
const string& tableAttributes ,
const string& tableDescriptio n) const
throw(TIDB_Exce ption)=0;

virtual void deleteFolder(co nst string& folderName) const
throw (TIDB_Exception ) = 0;

virtual void deleteTable(con st string& tableName) const
throw (TIDB_Exception ) = 0;

virtual IFolderManager* getFolderManage r(const string& folderName)
const
throw(TIDB_Exce ption)= 0;

virtual vector < IFolderManager >* getFolderManage rs() const
throw(TIDB_Exce ption) = 0;

virtual ITableManager* getTableManager (const string& tableName) const
throw(TIDB_Exce ption) = 0;

virtual vector < ITableManager >* getTableManager s() const
throw(TIDB_Exce ption)= 0;

virtual const string& getDescription( ) const =0;

virtual const string& getPath() const =0;

virtual const string& getVersion() const=0;

virtual ~IFolderManager () {} //dummy destructor
};
class FolderManagerCo mmon : public IFolderManager {
public:
virtual const string& getDescription( ) const;

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerC ommon();

protected:
virtual const IDatabase& getDatabase() const;

private:
string path;
string version;
string description;
IDatabase& database;
};

/**
* @stereotype Oracle
*/
class FolderManager : public FolderManagerCo mmon {

public:
FolderManager(c onst string& path, const IDatabase& database);

virtual IFolderManager* createFolder(co nst string& folderName,
const string& folderAttribute s,
const string& folderDescripti on) const
throw (TIDB_Exception );

virtual ITableManager* createTable(con st string& tableName,
ICondDBTable& table,
const string& tableAttributes ,
const string& tableDescriptio n) const
throw (TIDB_Exception );

virtual void deleteFolder(co nst string& folderName) const
throw (TIDB_Exception );

virtual void deleteTable(con st string& tableName) const
throw (TIDB_Exception );

virtual IFolderManager* getFolderManage r(const string& folderName)
const
throw (TIDB_Exception );

virtual vector < IFolderManager >* getFolderManage rs() const
throw (TIDB_Exception );

virtual ITableManager* getTableManager (const string& tableName) const
throw (TIDB_Exception );

virtual vector < ITableManager >* getTableManager s() const
throw (TIDB_Exception );

virtual ~FolderManager( );

private:

/** @link dependency */
/*# P_Folder lnkFolder; */

/** @link dependency */
/*# P_Table lnkTable; */
};
Jul 22 '05 #2
"Gama Franco" <ti***@cern.c h> wrote in message
news:41******** **************@ news.telepac.pt ...
Hi,

I've been developing this API, but now I get stuck in a compiling error
and I'm out of ideas. Some comments are welcome.

The hierarchy is bases in three classes, and I will explain it bellow in
detail.

The three classes are:
1 - IFolderManager -> abstract base class
2 - FolderManagerCo mmon : public IFolderManager
3 - FolderManager : public FolderManagerCo mmon

The properties of this relation are:

1 - IFolderManager has only abstract methods and no attributes.

2 - IFolderManagerC ommon implements a small set of methods from the base
class.
3 - IFolderManagerC ommon declares and implements some protected methods,
and as some private attributes.
4 - IFolderManagerC ommon has no constructors, since it is also an
abstract class (doesn't implement all the methods from the base class).
I just want to point out that abstract classes may need to have
constructors. In fact, in your case, I would expect IFolderManagerC ommon to
have constructors, because it has private data that it must initialize. If
you like, they may be protected, but they should still exist.
5 - FolderManager implements all the methods from the base class that
are not implemented by FolderManagerCo mmon.

6 - All the three classes have virtual destructors.
7 - All methods are virtual.
8 - Only FolderManager has constructors.

From this description we see that the union of FolderManagerCo mmon and
FolderManager implement all the methods declared by the interface (base
class).

The problem is that when I compile the code I get the following error:
../src/common/FolderManagerCo mmon.h:7: error: candidates are:
FolderManagerCo mmon::FolderMan agerCommon(cons t FolderManagerCo mmon&)

This error points to the constructor of FolderManager, in
FolderManager.c xx. And I have no ideia of what is going on.
You didn't provide the source to FolderManager.c xx, and it looks like you
didn't provide all of the compiler's messages. It's difficult to figure out
what the compiler's complaining about if you can't see the relevant
information. Consider posting that information if you aren't getting the
help you need.

<snip> class FolderManagerCo mmon : public IFolderManager {
public:
virtual const string& getDescription( ) const;

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerC ommon();

protected:
virtual const IDatabase& getDatabase() const;

private:
string path;
string version;
string description;
IDatabase& database;
};

<snip>

How do you expect "database" to be initialized? This class needs a
constructor.

--
David Hilsee
Jul 22 '05 #3
Hi,

I'm sorry to post with a different e-mail, but the Newsgroup's Server
of my ISP is not working and I had to use a (very) old google account.

There are some points that I don't understand. Why does an abstract
class need a constructor, and how can an abstract class have a
constructor?
For what I remember, it is not possible to create objects of an
abstract class... or is it?

Also, what is the definition of 'default constructor'? Is the one
without arguments?

The set of classes "Database" use the same technique (one Interface,
one Common and a final class)... the strange is that I don't get a
compiler error for those three classes, but that must happen because
of some detail that I don't know of.
I'm also not sure if the Database classe finish compilation, because
IDatabase 'includes' IFolderManager.
Now I post the compiler errors:

#########The one related to the constructor
.../src/Oracle/FolderManager.c xx: In constructor
`FolderManager: :FolderManager( const std::string&, const IDatabase&)':
.../src/Oracle/FolderManager.c xx:4: error: no matching function for
call to `FolderManagerC ommon::FolderMa nagerCommon()'

#########Relate d to the inheritence IFolderManager <--
FolderManagerCo mmon
.../src/common/FolderManagerCo mmon.h:7: error: candidates are:
FolderManagerCo mmon::FolderMan agerCommon(cons t FolderManagerCo mmon&)

Bellow I will post FolderManagerCo mmon.cxx and FolderManager.c xx

=============== =============== =============== =============== ====
FolderManagerCo mmon.cxx
=============== =============== =============== =============== ====
#include "FolderManagerC ommon.h"

const string& FolderManagerCo mmon::getDescri ption() const{
return this->description;
}

const string& FolderManagerCo mmon::getPath() const{
return this->path;
}

const string& FolderManagerCo mmon::getVersio n() const {
return this->version;
}

FolderManagerCo mmon::~FolderMa nagerCommon()
{
}

//protected methods
const IDatabase& FolderManagerCo mmon::getDataba se() const{
return this->database;
}
=============== =============== =============== =============== ====
FolderManager.c xx
=============== =============== =============== =============== ====
#include "FolderManager. h"

FolderManager:: FolderManager(c onst string& path, const IDatabase&
database)
{
//TODO
}

ITableManager* FolderManager:: getTableManager (const string& tableName)
const
throw (TIDB_Exception )
{
//TODO
return NULL;
}

vector < ITableManager >* FolderManager:: getTableManager s() const
throw (TIDB_Exception )
{
//TODO
return new vector < ITableManager >;
}

ITableManager* FolderManager:: createTable(con st string& tableName,
ICondDBTable& table,
const string& tableAttributes ,
const string& tableDescriptio n) const
throw (TIDB_Exception )
{
//TODO
return NULL;
}

void FolderManager:: deleteTable(con st string& tableName) const
throw (TIDB_Exception )
{
//TODO
}
void FolderManager:: deleteFolder(co nst string& folderName) const
throw (TIDB_Exception )
{
//TODO
}

IFolderManager* FolderManager:: createFolder(
const string& folderName,
const string& folderAttribute s,
const string& folderDescripti on) const
throw (TIDB_Exception )
{
//TODO
return new FolderManager( "/" + folderName, this->getDatabase()) ;
}

IFolderManager* FolderManager:: getFolderManage r(const string&
folderName) const
throw (TIDB_Exception ) {
//TODO
return new FolderManager( "/" + folderName, this->getDatabase()) ;
}

vector < IFolderManager >* FolderManager:: getFolderManage rs() const
throw (TIDB_Exception )
{
//TODO
return new vector<IFolderM anager >;
}

FolderManager:: ~FolderManager( )
{

}

Thanks in advance,
Gama Franco
Jul 22 '05 #4
Gama Franco wrote:
....
There are some points that I don't understand. Why does an abstract
class need a constructor, and how can an abstract class have a
constructor?
You can certainly have a constructor for an abstract class. The term
"abstract" class means that the class cannot be instantiated by itself.
For what I remember, it is not possible to create objects of an
abstract class... or is it?
It is if you inherit from it - but not by itself.

Also, what is the definition of 'default constructor'? Is the one
without arguments?
Yes. However, don't be confused by the default constructor provided by
the compiler and the default constructor that may be defined.

....

Now I post the compiler errors:

#########The one related to the constructor
../src/Oracle/FolderManager.c xx: In constructor
`FolderManager: :FolderManager( const std::string&, const IDatabase&)':
../src/Oracle/FolderManager.c xx:4: error: no matching function for
call to `FolderManagerC ommon::FolderMa nagerCommon()'

#########Relate d to the inheritence IFolderManager <--
FolderManagerCo mmon
../src/common/FolderManagerCo mmon.h:7: error: candidates are:
FolderManagerCo mmon::FolderMan agerCommon(cons t FolderManagerCo mmon&)

Bellow I will post FolderManagerCo mmon.cxx and FolderManager.c xx
....

This is your problem. You are defining a constructor which needs (and
will) instantiate the constructor for it's inherited classes (in this
case FolderManagerCo mmon ). In this case it seems like gcc does not
create a default constructor for FolderManagerCo mmon most likely because
you need to initialize FolderManagerCo mmon::database. Since
FolderManagerCo mmon::database is a reference it can only be bound by the
constructor and the compiler has no way of knowing how to do it and
hence it seems like gcc in this case simply does not provide a default
constructor. I'm not sure if this is what the standard requires but I
for one like this behaviour (because it's likely a bug to do anything
else anyway!).

FolderManager:: FolderManager(c onst string& path, const IDatabase&
database)
{
//TODO
}

You need to do somthing like this:
class FolderManagerCo mmon : public IFolderManager {
public:

FolderManagerCo mmon( const IDatabase& database )
: database( database )
{
}
....
const IDatabase& database;
};

FolderManager:: FolderManager(
const string& path, const IDatabase& database
)
: FolderManagerCo mmon( database )
{
//TODO
}
And all will be well.
Jul 22 '05 #5

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

Similar topics

18
1984
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point to the parent in the inheritance tree). 2. This hierarchy evolved over time to different versions for each class. So for example, version's 1 hierarchy would be A_v1 <-B_v1 <-..<-Z_v1. 3. At runtime, only one version is selected by a factory...
4
2901
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common example: class Vehicle {}
3
2473
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. My problem is that I have a /third/ class, CCommand, which derives from both IControl and ICommandmaster... The error message says (Weird.....)
0
1116
by: Bita-kookoo | last post by:
I am having a problem with inheritance for my web solution. Here are the steps I took for a project within C#: -I first created a new class, descended from System.Web.UI.Page. For this description, let's call this class "MyBasePage". Every webform page within my solution will descend from this class instead of System.Web.UI.Page. The reason for this is so that I have a common base class from which I can put custom validation,...
1
1199
by: Galileo | last post by:
I want to ask some questions about ASP, but not ASP. NET, sorry for my cross post because i don't know where asp newsgroup is First, is it possible to use user defined class in ASP, if so, how? and does ASP support something like inheritance? I know vb only support something like interface, is it the same as ASP? Is there any example for ASP inheritance or interface?
0
983
by: Mariano | last post by:
Hi, I have posted a bug of the forms designer that overwrites always the Icon, thus preventing Icon inheritance when you derive from a form. I am trying to overcome this by adding an ImageList in the base class. However, this doesn't solve my problem about Icon inheritance. The idea is to put Icon showing code inside the base form class. I add this code to the new() sub: 'Show the inherited icon Me.Icon = Icon.FromHandle((New...
9
3300
by: surendran.d | last post by:
hi, can diamond inhertance problem be solved using virtual functions,, or can only be done with scope resolution operators.. is there any other way to solve this problem... Thanks, suri
14
3622
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n should not be. But if I compile with g++-4.0.3 the following snippet: class A { int i;
9
10979
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
3
2902
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table: tlkpColor (PK) tlkpColorID
0
10228
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
10057
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...
1
7415
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
6676
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
5312
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...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
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
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.