Interview Questions

how to correctly instantiate this class: ......

Microsoft Interview Questions and Answers


(Continued from previous question...)

21. how to correctly instantiate this class: ......

Question:
how to correctly instantiate this class:
template < template < template < class > class, class > class Param >
struct Bogus {
int foo() {
printf("ok\n");;
}
};



maybe an answer:

'Foo' is a class which takes a template parameter which is itself a template. Hence we can declare 'Param' type as follows:

template < template < class > class X, class Y>
class Param { };

main() {

Foo< Param > tt;
tt.foo();
}

and the code is running


maybe an answer2:

template < template < int, int > class X>
struct Foo {
int foo() {
printf("ok\n");
return 0;
}};

template < int X, int Y >
class Param {
int x,y;
public:
Param(){x=X; y=Y;}
void printParam(){
cout<<x<<" "<<y<<"\n";
}
};

int main() {
Param<10, 20> p;
p.printParam();

Foo< Param> tt;
tt.foo();
return 0;
}

(Continued on next question...)

Other Interview Questions