Will the following code compile?
class Foo {
protected:
    int a;
};

template<class T> class Getter : public T {
public:
    int Get(int v) {return a;}
};

template<class T> class Setter : public T {
public:
    void Set(int v) {a = v;}
};

template<class T> void f1(Setter< T > f) {};
template<class T> void f2(Getter< T > f) {};

int main(int argc, char* argv[])
{    
    Getter< Foo > a;
    Setter< Foo > b;
    Setter< Getter< Foo > > c;

    f1(a);    // 1
    f2(a);    // 2

    f1(b);    // 3
    f2(b);    // 4

    f1(c);    // 5
    f2(c);    // 6

    return 0;
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes