473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor

Hello,

how do i have to call an inherited, templated class constructor from the
initializer list of the inheriting, non-templated class constructor?

example code:
template<typename T>
class A
{
protected:
sometype* something;
T something_else; /*gives the template some sense here*/
public:
A(sometype* param) : something(param) {};
}
class B : public A<int>
{
public:
B(sometype* param) : A(param) {}; // <== Compiler Error

/* further member functions */
}
The compiler always tries to identify A as a member variable not being
found, instead of the base class' constructor.
Nov 14 '08 #1
4 5517
On Nov 14, 3:30*pm, "l.s.rock...@web.de" <l.s.rock...@web.dewrote:
Hello,

how do i have to call an inherited, templated class constructor from the
initializer list of the inheriting, non-templated class constructor?

example code:

template<typename T>
class A
{
protected:
* * * * sometype* something;
* * * * T something_else; * * * /*gives the template some sense here*/
public:
* * * * A(sometype* param) : something(param) {};

}

class B : public A<int>
{
public:
* * * * B(sometype* param) : A(param) {}; // <== Compiler Error

* * * * /* further member functions */

}

The compiler always tries to identify A as a member variable not being
found, instead of the base class' constructor.
The following is a class:

class A { };

this is not:

class A { }

The following declares a class and defines a constructor:

class A
{
A() { }
};

or

// A.hpp (missing include guards)
class A
{
A(); // declaration only
};

// A.cpp
A::A() { } // definition

Basically, a semicolon denotes a declaration.
Nov 14 '08 #2
Salt_Peter wrote:
On Nov 14, 3:30 pm, "l.s.rock...@web.de" <l.s.rock...@web.dewrote:
>Hello,

how do i have to call an inherited, templated class constructor from the
initializer list of the inheriting, non-templated class constructor?

example code:

template<typename T>
class A
{
protected:
sometype* something;
T something_else; /*gives the template some sense here*/
public:
A(sometype* param) : something(param) {};

}

class B : public A<int>
{
public:
B(sometype* param) : A(param) {}; // <== Compiler Error

/* further member functions */

}

The compiler always tries to identify A as a member variable not being
found, instead of the base class' constructor.

The following is a class:

class A { };

this is not:

class A { }

The following declares a class and defines a constructor:

class A
{
A() { }
};

or

// A.hpp (missing include guards)
class A
{
A(); // declaration only
};

// A.cpp
A::A() { } // definition

Basically, a semicolon denotes a declaration.
That's not the point. I just forgot the semicolons in the example.

I found out, that my problem is not only specific to explicit
constructor calls, but occurs everytime I want to call a polymorph
member function of the base class (which is a template class).

I get an undefined reference error from ld.

That's why I start a new post for the more general problem description.
Nov 15 '08 #3
l.*********@web.de wrote:
Salt_Peter wrote:
>On Nov 14, 3:30 pm, "l.s.rock...@web.de" <l.s.rock...@web.dewrote:
>>Hello,

how do i have to call an inherited, templated class constructor from the
initializer list of the inheriting, non-templated class constructor?

example code:

template<typename T>
class A
{
protected:
sometype* something;
T something_else; /*gives the template some sense here*/
public:
A(sometype* param) : something(param) {};

}

class B : public A<int>
{
public:
B(sometype* param) : A(param) {}; // <== Compiler Error

/* further member functions */

}

The compiler always tries to identify A as a member variable not being
found, instead of the base class' constructor.

The following is a class:

class A { };

this is not:

class A { }

The following declares a class and defines a constructor:

class A
{
A() { }
};

or

// A.hpp (missing include guards)
class A
{
A(); // declaration only
};

// A.cpp
A::A() { } // definition

Basically, a semicolon denotes a declaration.

That's not the point. I just forgot the semicolons in the example.

I found out, that my problem is not only specific to explicit
constructor calls, but occurs everytime I want to call a polymorph
member function of the base class (which is a template class).

I get an undefined reference error from ld.
That's why I start a new post for the more general problem description.
Okay, the problem was that I have used neither the import nor the export
model for template source code organization[1].

I chose the import model and moved the definitions of the template class
member funtions into the header file and everything works.

[1] http://www.ddj.com/cpp/184401563
Nov 15 '08 #4
l.*********@web.de wrote:
Salt_Peter wrote:
>On Nov 14, 3:30 pm, "l.s.rock...@web.de" <l.s.rock...@web.dewrote:
>>Hello,

how do i have to call an inherited, templated class constructor from the
initializer list of the inheriting, non-templated class constructor?

example code:

template<typename T>
class A
{
protected:
sometype* something;
T something_else; /*gives the template some sense here*/
public:
A(sometype* param) : something(param) {};

}

class B : public A<int>
{
public:
B(sometype* param) : A(param) {}; // <== Compiler Error

/* further member functions */

}

The compiler always tries to identify A as a member variable not being
found, instead of the base class' constructor.

The following is a class:

class A { };

this is not:

class A { }

The following declares a class and defines a constructor:

class A
{
A() { }
};

or

// A.hpp (missing include guards)
class A
{
A(); // declaration only
};

// A.cpp
A::A() { } // definition

Basically, a semicolon denotes a declaration.

That's not the point. I just forgot the semicolons in the example.

I found out, that my problem is not only specific to explicit
constructor calls, but occurs everytime I want to call a polymorph
member function of the base class (which is a template class).

I get an undefined reference error from ld.
That's why I start a new post for the more general problem description.
Okay, the problem was that I have used neither the import nor the export
model for template source code organization[1].

I chose the import model and moved the definitions of the template class
member funtions into the header file and everything is working now.

[1] http://www.ddj.com/cpp/184401563
Nov 15 '08 #5

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

Similar topics

1
by: petards | last post by:
I am inheriting from a form that has a tab control on it. The tab control has two pages. I can't seem to access the second page in the designer for the inherited form in order to drop controls on...
0
by: Patrick Corkum | last post by:
Hello, I am having a really annoying problem. I have a base form, say FormA, and this form has some buttons on it with images (which are stored in the resx file). I then have FormB, which...
8
by: ThomasR | last post by:
I understand that virtual methods on inherited objects are slower than non-virtual methods because of the indirection required to support the call. However, when looking at IL code produced by...
1
by: Boniek | last post by:
Hi Sometimes I have problems with my forms which are inherited from other forms and base forms are in other project. When I change something in base forms my normal forms are broken in Visual in...
0
by: Wizou | last post by:
1. Create a TcpListener 2. Start a child Process 3. Kill the parent process => You can't bind to the port until you close the child process Variant : 3. Terminate normally the parent process...
0
by: seven | last post by:
I have a base page with an HTMLForm object (added to the base page control heiarchy during Init). In the design of pages derived from this base page, I can choose to create controls and add them...
3
by: John A. Prejean | last post by:
This one has me stumped. I have a base form I am trying to wrap up, but I have one problem. In two functions I am opening a "record detail" form. I would like to keep the code in the base form...
3
by: DaTurk | last post by:
Is it possible to have a property defined in one interface, with just the get portioned stubbed out, and then in an interface inheriting from that interface declare the set portion of the inherited...
4
by: Mikus Sleiners | last post by:
I can't seem to add new controls to form that is inherited from another form. I have BaseForm wich have table layout on it 2 panelsm and some buttons. Now i create InheritedForm : BaseForm and...
35
by: jleslie48 | last post by:
I've written a cgi program in C using the borland 5.5 free compiler, and it runs just fine on an Apache server. My only issue is if I issue some system calls the cgi suspends until the call...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.