473,965 Members | 23,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Virtual Member templates

I wanted to know why member templates cannot be virtual -
is it because there is a conceptual impossibility in having them, or is
it because the current mechanism of implementaing virtual functons
would not work with that concept?

Assuming that a compiler doesnot support "export" keyword, I guess it
is necessary that all instantiations of the member template must get
the definition of the template (and hence the definition of the class
of which it is a member) at compile time. In such a case, it is
certainly not impossible for the linker to combine up the vtables to
generate a final entry (it is no different than combining individual
symbol tables, geneate a new one and resolve references.)

I might not be technically correct in what I have written above. So
please correct me if I am writing nonsense.

Thanks a lot.

Nov 11 '05 #1
2 2239
* Neelesh:
I wanted to know why member templates cannot be virtual -
is it because there is a conceptual impossibility in having them, or is
it because the current mechanism of implementaing virtual functons
would not work with that concept?


More that the C++ template mechanism is unconstrained, so that a
templated virtual function corresponds to an infinite number of
potential virtual functions, and you need whole program analysis to
determine which ones are actualized, and whole program analysis isn't
well supported by conventional C and C++ separate compilation.

In addition, outside the standard but well inside the realm of general
practical C++ usage, there is the problem of dynamic libraries.

With templated virtual functions a dynamic library would require dynamic
back-patching somewhere, to provide at run-time the equivalent of or a
substitute for the static whole program analysis.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 11 '05 #2
Ian
Neelesh wrote:
I wanted to know why member templates cannot be virtual -
is it because there is a conceptual impossibility in having them, or is
it because the current mechanism of implementaing virtual functons
would not work with that concept?

Assuming that a compiler doesnot support "export" keyword, I guess it
is necessary that all instantiations of the member template must get
the definition of the template (and hence the definition of the class
of which it is a member) at compile time. In such a case, it is
certainly not impossible for the linker to combine up the vtables to
generate a final entry (it is no different than combining individual
symbol tables, geneate a new one and resolve references.)

It's not possible as all possible instantiations of the template would
have to be known when the class was compiled.

Ian
Nov 11 '05 #3

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

Similar topics

4
4661
by: Sat | last post by:
Hi, I have a simplified version of a problem that I am facing (hope I haven't oversimplified it). This code doesn't work now and I want to find how I can make it work. Can I call the derived class version from the base class pointer and still be able to use a vector with derived element pointers? class BaseElem { }; class DerivedElem1 { };
4
1865
by: Martin | last post by:
Greetings I want to have virtual member functionality, but without my member functions being virtual:-) As of yet this is all just in my head cause I can't see a nice solution yet so lets start with some simple code.
2
2838
by: Amadeus W. M. | last post by:
Template member functions cannot be virtual - I know - but is there any way to simulate that (other than making the entire class templated, with non-templated members). What I have is this: class Transform { public:
5
2975
by: dj | last post by:
I somehow understand why member function templates cannot be virtual, but my question is how I could achieve something similar to this: class A { public: template<typename Tvirtual f() = 0; } class B : public A { public:
2
1879
by: Heinz Ketchup | last post by:
Hello, I'm looking to bounce ideas off of anyone, since mainly the idea of using Multiple Virtual Inheritance seems rather nutty. I chalk it up to my lack of C++ Experience. Here is my scenario... I have 5 Derived Classes I have 3 Base Classes
7
2138
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from BufferBase, and customized in order to be able to a type of data (of any kind, such as chunks of audio samples from a sound card). The processor classes are derived from ProcessorBase, and are customized to handle BufferBase-derived objects. Each...
11
2767
by: mathieu | last post by:
Hi there, I don't think I'll be able to describe my issue correctly, so instead I'll just give a pseudo C++ code I am struggling with. Basically I am looking for a 'pure virtual template' function that I would be able to declare in the base class (*). Thanks for suggestions, -Mathieu
13
7291
by: Mike -- Email Ignored | last post by:
Is a pure virtual function in allowed in a template base class? In any case, I have one working. Am I skating on thin ice? Thanks, Mike.
5
2968
by: want.to.be.professer | last post by:
For OO design, I like using virtual member function.But considering efficiency, template is better. Look at this program, class Animal { public: virtual void Walk() = 0; }; class Dog
0
10130
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
11780
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
10851
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10047
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
8420
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
7567
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
6367
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
6506
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5107
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

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.