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: unassig...@gcc.gnu.org
        ReportedBy: benedikt...@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.

Reply via email to