473,387 Members | 1,903 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.

Non-template class from a template base class with pure virtual methods

Hello everyone,

I'm facing a particular situation about template class derivation.
The subject is old -- deriving a non-template class from a template
base class -- but my problem is that the base class has a pure virtual
method. For instance:

template<class T>
class A {
public:
virtual void method() = 0;
};

class B : public A<int{
public:
// neither of the following worked:
// void method() { }
// void method<int>() { }
// template<intmethod() { }
};

int main(int argc, char *argv[]) {
B b;
return 0;
}

This is probably simple, but I couldn't figure out a way to implement
the derived method.

Also, I don't know if this matters, but I'd better stay apart from
compiler idiosyncrasies -- I'm searching for something portable, at
least between g++3.4.4 and VC7.

Does anybody have any hint about this?

--
Best regards,
Vilar Camara Neto

Mar 25 '07 #1
2 4213
vi*******@gmail.com wrote:
Hello everyone,

I'm facing a particular situation about template class derivation.
The subject is old -- deriving a non-template class from a template
base class -- but my problem is that the base class has a pure virtual
method. For instance:

template<class T>
class A {
public:
virtual void method() = 0;
};

class B : public A<int{
public:
// neither of the following worked:
// void method() { }
Actually, the above looks right and works for me. What error do you get?
// void method<int>() { }
// template<intmethod() { }
};

int main(int argc, char *argv[]) {
B b;
return 0;
}

This is probably simple, but I couldn't figure out a way to implement
the derived method.

Also, I don't know if this matters, but I'd better stay apart from
compiler idiosyncrasies -- I'm searching for something portable, at
least between g++3.4.4 and VC7.

Does anybody have any hint about this?
Try the following with your compilers:

#include <iostream>

template<class T>
class A {
public:
virtual void method() = 0;
};

class B : public A<int{
public:
void method() { std::cout << "hi!\n"; }
};

int main(int argc, char *argv[]) {
B b;
b.method();
return 0;
}
Best

Kai-Uwe Bux
Mar 25 '07 #2
On 25 mar, 14:29, Kai-Uwe Bux <jkherci...@gmx.netwrote:
template<class T>
class A {
public:
virtual void method() = 0;
};
class B : public A<int{
public:
// neither of the following worked:
// void method() { }

Actually, the above looks right and works for me. What error do you get?
Shame on me, sorry. I was actually compiling+linking with gcc, which
was giving me linking errors. The problem is that "-lstdc++" isn't
implied when using gcc. (The fact that there were no compiling errors
gave me the impression that gcc would behave exactly as g++, according
to the source file extension.)

With g++ I've got no linking errors and everything works great.

Even so, your "this works for me" was a key point to understand the
problem. Thank you, Bux.

--
Regards,
Vilar Camara Neto

Mar 25 '07 #3

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
4
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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
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...
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
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...
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.