473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create 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 - FolderManagerCommon : public IFolderManager
3 - FolderManager : public FolderManagerCommon

The properties of this relation are:

1 - IFolderManager has only abstract methods and no attributes.

2 - IFolderManagerCommon implements a small set of methods from the base
class.
3 - IFolderManagerCommon declares and implements some protected methods,
and as some private attributes.
4 - IFolderManagerCommon 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 FolderManagerCommon.

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 FolderManagerCommon 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/FolderManagerCommon.h:7: error: candidates are:
FolderManagerCommon::FolderManagerCommon(const FolderManagerCommon&)

This error points to the constructor of FolderManager, in
FolderManager.cxx. 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(const string& folderName,
const string& folderAttributes,
const string& folderDescription) const
throw (TIDB_Exception) =0;

virtual ITableManager* createTable(const string& tableName,
ICondDBTable& table,
const string& tableAttributes,
const string& tableDescription) const
throw(TIDB_Exception)=0;

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

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

virtual IFolderManager* getFolderManager(const string& folderName)
const
throw(TIDB_Exception)= 0;

virtual vector < IFolderManager >* getFolderManagers() const
throw(TIDB_Exception) = 0;

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

virtual vector < ITableManager >* getTableManagers() const
throw(TIDB_Exception)= 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
--------------------------------------------------------------
IFolderManagerCommon.h
--------------------------------------------------------------
#ifndef FOLDERMANAGERCOMMON_H
#define FOLDERMANAGERCOMMON_H

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

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

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerCommon();

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/FolderManagerCommon.h"

/**
* @stereotype Oracle
*/
class FolderManager : public FolderManagerCommon {

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

virtual IFolderManager* createFolder(const string& folderName,
const string& folderAttributes,
const string& folderDescription) const
throw (TIDB_Exception);

virtual ITableManager* createTable(const string& tableName,
ICondDBTable& table,
const string& tableAttributes,
const string& tableDescription) const
throw (TIDB_Exception);

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

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

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

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

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

virtual vector < ITableManager >* getTableManagers() 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 1380
Gama Franco wrote:
....

The problem is that when I compile the code I get the following error:
../src/common/FolderManagerCommon.h:7: error: candidates are:
FolderManagerCommon::FolderManagerCommon(const FolderManagerCommon&)

This error points to the constructor of FolderManager, in
FolderManager.cxx. And I have no ideia of what is going on.
It seems you have missed putting FolderManager.cxx 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(const string& folderName,
const string& folderAttributes,
const string& folderDescription) const
throw (TIDB_Exception) =0;

virtual ITableManager* createTable(const string& tableName,
ICondDBTable& table,
const string& tableAttributes,
const string& tableDescription) const
throw(TIDB_Exception)=0;

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

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

virtual IFolderManager* getFolderManager(const string& folderName)
const
throw(TIDB_Exception)= 0;

virtual vector < IFolderManager >* getFolderManagers() const
throw(TIDB_Exception) = 0;

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

virtual vector < ITableManager >* getTableManagers() const
throw(TIDB_Exception)= 0;

virtual const string& getDescription() const =0;

virtual const string& getPath() const =0;

virtual const string& getVersion() const=0;

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

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerCommon();

protected:
virtual const IDatabase& getDatabase() const;

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

/**
* @stereotype Oracle
*/
class FolderManager : public FolderManagerCommon {

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

virtual IFolderManager* createFolder(const string& folderName,
const string& folderAttributes,
const string& folderDescription) const
throw (TIDB_Exception);

virtual ITableManager* createTable(const string& tableName,
ICondDBTable& table,
const string& tableAttributes,
const string& tableDescription) const
throw (TIDB_Exception);

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

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

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

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

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

virtual vector < ITableManager >* getTableManagers() 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.ch> 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 - FolderManagerCommon : public IFolderManager
3 - FolderManager : public FolderManagerCommon

The properties of this relation are:

1 - IFolderManager has only abstract methods and no attributes.

2 - IFolderManagerCommon implements a small set of methods from the base
class.
3 - IFolderManagerCommon declares and implements some protected methods,
and as some private attributes.
4 - IFolderManagerCommon 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 IFolderManagerCommon 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 FolderManagerCommon.

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 FolderManagerCommon 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/FolderManagerCommon.h:7: error: candidates are:
FolderManagerCommon::FolderManagerCommon(const FolderManagerCommon&)

This error points to the constructor of FolderManager, in
FolderManager.cxx. And I have no ideia of what is going on.
You didn't provide the source to FolderManager.cxx, 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 FolderManagerCommon : public IFolderManager {
public:
virtual const string& getDescription() const;

virtual const string& getPath() const;

virtual const string& getVersion() const;

virtual ~FolderManagerCommon();

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.cxx: In constructor
`FolderManager::FolderManager(const std::string&, const IDatabase&)':
.../src/Oracle/FolderManager.cxx:4: error: no matching function for
call to `FolderManagerCommon::FolderManagerCommon()'

#########Related to the inheritence IFolderManager <--
FolderManagerCommon
.../src/common/FolderManagerCommon.h:7: error: candidates are:
FolderManagerCommon::FolderManagerCommon(const FolderManagerCommon&)

Bellow I will post FolderManagerCommon.cxx and FolderManager.cxx

================================================== ==============
FolderManagerCommon.cxx
================================================== ==============
#include "FolderManagerCommon.h"

const string& FolderManagerCommon::getDescription() const{
return this->description;
}

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

const string& FolderManagerCommon::getVersion() const {
return this->version;
}

FolderManagerCommon::~FolderManagerCommon()
{
}

//protected methods
const IDatabase& FolderManagerCommon::getDatabase() const{
return this->database;
}
================================================== ==============
FolderManager.cxx
================================================== ==============
#include "FolderManager.h"

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

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

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

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

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

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

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

vector < IFolderManager >* FolderManager::getFolderManagers() const
throw (TIDB_Exception)
{
//TODO
return new vector<IFolderManager >;
}

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.cxx: In constructor
`FolderManager::FolderManager(const std::string&, const IDatabase&)':
../src/Oracle/FolderManager.cxx:4: error: no matching function for
call to `FolderManagerCommon::FolderManagerCommon()'

#########Related to the inheritence IFolderManager <--
FolderManagerCommon
../src/common/FolderManagerCommon.h:7: error: candidates are:
FolderManagerCommon::FolderManagerCommon(const FolderManagerCommon&)

Bellow I will post FolderManagerCommon.cxx and FolderManager.cxx
....

This is your problem. You are defining a constructor which needs (and
will) instantiate the constructor for it's inherited classes (in this
case FolderManagerCommon ). In this case it seems like gcc does not
create a default constructor for FolderManagerCommon most likely because
you need to initialize FolderManagerCommon::database. Since
FolderManagerCommon::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(const string& path, const IDatabase&
database)
{
//TODO
}

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

FolderManagerCommon( const IDatabase& database )
: database( database )
{
}
....
const IDatabase& database;
};

FolderManager::FolderManager(
const string& path, const IDatabase& database
)
: FolderManagerCommon( 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
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...
4
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...
3
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. ...
0
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...
1
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?...
0
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...
9
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
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...
9
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
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:...
0
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,...
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
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...
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...
0
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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...

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.