views:

84

answers:

1

I have an interface and a couple of implementations of a class that stores serialized objects. I'd like to make the implementation classes into template classes so I can use them with more than one type of object, but I'm getting compiler errors.

#include <iostream>
template<typename T>
class Interface{
public:
    virtual void func(T& c) = 0;
};

class Container{
public:
    Container() : dummy(10){}
    int dummy;
};


template<typename T>
class Implementation : public Interface{
public:
    void func(T& c){
        std::cout << "++c.dummy " << ++c.dummy << std::endl;
    }
};

int main(){
    Container c;
    Implementation<Container> i;
    i.func(c);
    return 0;
}

I get "error: expected class-name before ‘{’ token" at the "class Implementation..." line.

Thanks.

+9  A: 
template<typename T>
class Implementation : public Interface<T> {
//                                     ^^^
KennyTM
Your `^^^` is a tad misaligned. I think.
strager
@strager: Looks fine here with Consolas. It should be directly below the `<T>`.
KennyTM
@Strager: as long as the ^^^ points at the <T> after Interface, it is correctly aligned.
Sjoerd
Ah; I have Opera scaled at 150%, which for some reason cause misalignments. At 100% it's fine. Weird...
strager