This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52978] New: Inherit from Template with specified type and override virtual function
- From: "benediktibk at aon dot at" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 13 Apr 2012 16:29:43 +0000
- Subject: [Bug c++/52978] New: Inherit from Template with specified type and override virtual function
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52978
Bug #: 52978
Summary: Inherit from Template with specified type and override
virtual function
Classification: Unclassified
Product: gcc
Version: 4.5.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: benediktibk@aon.at
Created attachment 27153
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27153
preprocessed file
I tried to inherit from an template, but with an specified type. In this
derived class a virtual function from the base (the template class) is
overriden. During compile gcc complains about a pure virtual function if I try
to instantiate an object from the derived type.
I compiled the code with the following statement:
gcc -Wall -Wextra -save-temps -lstdc++ main.cpp
The code looks like this:
#include <stdio.h>
template<class T>
class Foo
{
public:
virtual void blub(const T &value) const = 0;
};
class Bar : public Foo<int*>
{
public:
virtual void blub(const int* &value) const
{
printf("\n%i\n", *value);
}
};
int main(int argc, char **argv)
{
Bar bar;
const int *one = new int;
bar.blub(one);
return 0;
}
The output from the compiler was that:
main.cpp: In Funktion Âint main(int, char**)Â:
main.cpp:21:7: Fehler: Variable Âbar kann nicht als vom abstrakten Typ ÂBarÂ
deklariert werden
main.cpp:11:1: Anmerkung: because the following virtual functions are pure
within ÂBarÂ:
main.cpp:7:20: Anmerkung: void Foo<T>::blub(const T&) const [with T =
int*]
main.cpp: At global scope:
main.cpp:19:5: Warnung: unbenutzter Parameter ÂargcÂ
main.cpp:19:5: Warnung: unbenutzter Parameter ÂargvÂ
make: *** [all] Fehler 1
Im running gcc version 4.5.3-r2 on Gentoo.