Issue with Templates and inheritance

I have an interface (i.e base class) like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template <typename A, typename B>
class IBase
{
public:
  struct MyStruct {
    uint32_t var1;
    B var2;
  };

  enum MyEnum {
    ENUM0,
    ENUM1,
    ENUM2
  };

  IBase() = 0;
  ~IBase() { }

  virtual void GetInfo(MyStruct& structVar) throw () = 0;
};


And I have its implementation (i.e. a derived class) as follows:

1
2
3
4
5
6
7
8
9
10
template <typename A, typename B>
class Derived : public IBase <A, B>
{
protected:
  typedef std::set< IBase::<A, B>::MyStruct > MyNewType;

public:

  virtual void GetInfo(IBase::<A, B>MyStruct& structVar) throw ();
};


I have two problems with this code:

1. In the derived class declaration, it fails in the typedef. I get the following errors:
error: template argument 1 is invalid
error: template argument 2 is invalid

2. In the function declaration of GetInfo, I get an error as well:
IBase::MyStruce is not a type.

Any ideas about what I'm doing wrong here ?
BTW I'm using g++ 4.3.2 x86_64 to compile the code, if that is of any information.
To start with:

In the following declarations:

1
2
3
4
5
6
protected:
  typedef std::set< IBase::<A, B>::MyStruct > MyNewType; // the <A, B> is in the wrong place

public:

  virtual void GetInfo(IBase::<A, B>MyStruct& structVar) throw ();// the <A, B> is in the wrong place 


Oops, my bad.... Okay now I have changed these two statements as

1
2
3
4
5
6
protected:
  typedef std::set< IBase<A, B>::MyStruct > MyNewType; // the <A, B> is in the wrong place

public:

  virtual void GetInfo(IBase<A, B>::MyStruct& structVar) throw ();


Now I get these kinda errors for the first case:
1
2
3
type/value mismatch at argument 1 in template parameter list for `template<class _Tp, class _Alloc> class std::vector
expected a type, got IBase<A, B>::MyStruct
template argument 2 is invalid



And for the second:
class IBase<A, B>::MyStruct is not a type
Last edited on
Use:

1
2
3
4
typedef typename IBase<A,B>::MyStruct MyStruct;
typedef std::set<MyStruct> MyNewtype;

virtual void GetInfo( MyStruct& );


(ps - and skip the exception specification)
And don't forget to make ~IBase() virtual.
Topic archived. No new replies allowed.