473,387 Members | 3,821 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,387 software developers and data experts.

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 2207
* 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
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...
4
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...
2
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: ...
5
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; }...
2
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...
7
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...
11
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'...
13
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
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
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.