help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unexpected error when using hierarchy of template classes


From: JH Trauntvein
Subject: Unexpected error when using hierarchy of template classes
Date: 26 Sep 2005 12:29:46 -0700
User-agent: G2/0.2

I have code that I am trying to port from visual studio .NET to g++
4.0.1 (Fedora core 4) that involves template classes that extend other
template classes through inheritance.  An example of this pattern is
given in a code fragment at the end of this posting.  This fragment (as
well as the code that I am trying to port) fails to compile with the
following error message:

test.cpp: In member function 'virtual void NativeValue<storage_len,
type_code>::f(std::ostream&)':
test.cpp:13: error: object missing in reference to 'Value::storage'
test.cpp:31: error: from this location

Admittedly, in this context, the inheritance hierarchy seems rather
contrived.  I believe that the hiearchy makes better sense when other
methods are filled in.  This is the minimum that I could do to
re-create the compile error.


Regards,

Jon Trauntvein


#include <iostream>


typedef unsigned long uint4;


class Value
{
public:
   virtual void f(std::ostream &out) = 0;

protected:
   void *storage;
};


template<uint4 storage_req,
         int native_type_code,
         int translated_type_code>
class SimpleValue: public Value
{
};


template<uint4 storage_len,
         int type_code>
class NativeValue: public SimpleValue<storage_len,type_code,type_code>
{
public:
   virtual void f(std::ostream &out)
   { out << Value::storage; }
};


class UInt4Value: public NativeValue<4,1>
{
public:
   virtual void f(std::ostream &out)
   {
      uint4 *val = static_cast<uint4 *>(storage);
      out << *val;
   }
};


int main()
{ return 1; }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]