473,857 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me 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 5568
On Nov 14, 3:30*pm, "l.s.rock...@we b.de" <l.s.rock...@we b.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<typena me 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...@we b.de" <l.s.rock...@we b.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<typen ame 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...@we b.de" <l.s.rock...@we b.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<type name 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...@we b.de" <l.s.rock...@we b.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<type name 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
328
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 it. Any ideas? Thanks.
0
1302
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 inherits from FormA. FormB for some odd <and stupid> reason, FormB desides to rewrite all the designer generated code for the inherited controls. It also puts the images that FormA has in it's resx into it's own resx <very annoying>. I have MANY forms...
8
3861
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 the compiler, I notice that all methods on object variables use callvirt instead of call, regardless of whether the method is truly virtual or not. I assume this allows .NET to check if the object reference is null or not before invoking the...
1
1536
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 designing. Maybe inherited forms aren't compatible with base forms but I don't know how and what. I compile all projects and everything is ok. When I open one form I see a message like that "Member not found". I don't know what member and where...
0
1262
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 => The parent process stays as "Running" until the child process is closed
0
1304
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 to the HTMLForm object I'm inheriting, to create a postback form. And on one particular page I'm doing just that; defining controls on the derived page (during Init) and adding these controls to the inherited HTMLForm object's control...
3
1542
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 and pass info to the form telling it which from to actually open. Any ideas how to do this? Here is an example of what I had in mind if the text isn't clear enough... Base Form Function EditRecord() Dim frmRecord as New Form()
3
1884
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 stubbed out property? So that only classes implementing the second interface can set properties?
4
16276
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 want to add some new controls and add them to pannels but i can't drag and drop them ... designer does not allow me. Why is that ? Panels and table layout modifiers is set to public.
35
4603
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 finishes. for example if in my c program I have a line: system("notepad"); I can see with the taskmanager that an instance of notepad.exe is
0
9923
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
11082
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
10711
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...
0
9549
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
7939
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
7104
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
5774
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
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3215
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.