473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

methods inherited from template superclass

Hi,

I have a class which inherits from a template (vector). This class is
defined in the header file as below.

Output.h

class _DLL_RESPONSE_S ERVER Output : public vector<SingleOu tput>
{
public:
Output();
const string& getActualText() const {return m_actualText;}
void insert(const SingleOutput& so);
}

The "Output::Insert " is defined in a CPP file separately.
Output.cpp

void ResponseServer: :Output::insert (const ResponseServer: :SingleOutput&
so)
{
// doSomething
}

That code gets compiled into a "LIB" and a "DLL".

When i try to use the Output.h in another project and try to link to
the LIB, i get an external symbols unresolved error for the size()
method.

Is this because templates will have some kind of inlining ?

What am i missing here ? Wont the "size()" method defined in the
template vector

1) either get compiled into the Output.LIB
2) OR will it not be picked up in the target consumer project where i
have access to the Output.h and to the Vector LIB/H as well. How do i
need to setup the consumer project to use the Output.LIB and at the
same time have definitions even for the superclass template?

Thanks
Nishith

Feb 14 '06 #1
1 1277
Nishith Prabhakar wrote:
Hi,

I have a class which inherits from a template (vector). This class is
defined in the header file as below.

Output.h

class _DLL_RESPONSE_S ERVER Output : public vector<SingleOu tput>
{
public:
Output();
const string& getActualText() const {return m_actualText;}
void insert(const SingleOutput& so);
}
This is a bad idea for at least three reasons:

1. Using std::containers (or even std::string) in DLL interfaces ties
users of your DLL to a specific compiler, library, version and CRT.
There is not much point in having a DLL under these circumstances - why
not make it a static lib?
2. Inheriting publically from std::containers is generally not a good
idea, since they have no virtual functions so it is not possible to
introduce any new invariants, etc. Better to either:
a) Have the vector as a member, and just add the member functions you
actually need. Or,
b) Just use std::vector directly, and write some namespace scope
functions to operate on the vector.
3. Your insert function "hides" vector::insert - hiding is rarely a good
idea.
The "Output::Insert " is defined in a CPP file separately.
Output.cpp

void ResponseServer: :Output::insert (const ResponseServer: :SingleOutput&
so)
{
// doSomething
}

That code gets compiled into a "LIB" and a "DLL".
Any reason why not just a lib?
When i try to use the Output.h in another project and try to link to
the LIB, i get an external symbols unresolved error for the size()
method.

Is this because templates will have some kind of inlining ?
I think it's probably because you haven't exported vector. Try adding this:

template class _DLL_RESPONSE_S ERVER std::vector<Sin gleOutput>;

You also need to export SingleOutput of course, if you aren't already.
What am i missing here ? Wont the "size()" method defined in the
template vector

1) either get compiled into the Output.LIB
Only if you specify that it should.
2) OR will it not be picked up in the target consumer project where i
have access to the Output.h and to the Vector LIB/H as well. How do i
need to setup the consumer project to use the Output.LIB and at the
same time have definitions even for the superclass template?


I think it doesn't look, since it assumes it will be in the DLL. Not too
sure about this.

Still, rather than all this hassle, the right way to do a DLL is to either:
1) Have a simple C API, possibly providing a C++ facade at the client
side to simplify ease of use (and hopefully even provide for dynamic
loading of the DLL).
2) Use COM, or a similar technology.

That way you aren't completely tied to a particular compiler version.

Tom
Feb 14 '06 #2

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

Similar topics

5
1845
by: Arnd Baecker | last post by:
Hi, the summary of my question is: is there a way to append commands to a method inherited from another class? More verbose: Assume the following situation that I have a class class_A with several methods. In each of these methods quite a few computations take place and several variables are defined.
99
5924
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less important changes, so in this thread I would like to focus on that issue alone. I have edited the Proposed Syntax example below to take out the changes unecessary to this discussion. I left in the change of "instance variable" syntax (...
7
8668
by: Tron Thomas | last post by:
Under the right compiler the following code: class Base { public: virtual void Method(int){} }; class Derived: public Base {
2
3036
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass' priviledged methods also. Do you know if this is possible ? In the following example, I create an ObjectA (variable a), an ObjectB which inherits ObjectA (variable b) and an ObjectC which inherits ObjectA (variable c1). The 'toString ()' method...
32
4526
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
5
4641
by: Earl Teigrob | last post by:
Is there a way to rename the public properties of a inherited class? I am inheriting an asp.net control (class) and am adding addtional functionality. (in this case, up to 3 borders on an imagebutton control) I would like to change the name of the BorderColor property to InnerBorderColor because it would make more sense in the context of this this new control. Thanks Earl
4
1703
by: Xavier Décoret | last post by:
I have just come across the following fact. Names defined in a template superclass of the current template must be qualified as being from the superclass. Alternatively, you can also qualify those names by preceding them with this->. An example might be clearer to read: template <typename T> struct Base {
5
3832
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
1
1940
by: UptownYardy | last post by:
Hi excuse the mistake in the title. I'm having trouble on inheriting methods from a superclass in Java. Basically I've forgotten how to. I want to inherit 3 methods from the Artwork superclass to be used in the Print subclass. The reason being I want to add an extra parameter (printNumber) to these methods in the Print Class. This section of code from the Artwork class is what I want to be inherited: /** * Prints an Artwork piece to the...
0
9595
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
9432
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,...
0
8891
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
7420
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
6682
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
5313
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.