#include <iostream>
using namespace std;
template < typename T> class Stack {
typedef typename T:: ThisDoesntExist StaticAssert; // T::NotExisting doesn't exist at all!
} ;
void f1( Stack< char > ) ; // No instantiation, compiles
class Exercise {
//Stack<double> &rsd; // No instantiation, compiles (references don't need instantiation, are similar to pointers in this)
Stack< int > si; // Instantiation! Doesn't compile!!
} ;
int main( ) {
Stack< char > * sc; // No Instantiation, this compiles successfully since a pointer doesn't need instantiation
//f1(*sc); // Instantiation of char! Doesn't compile!!
//int iObj = sizeof(Stack< std::string >); // Instantiation of std::string, doesn't compile!!
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPiBjbGFzcyBTdGFjayB7CiAgdHlwZWRlZiB0eXBlbmFtZSBUOjpUaGlzRG9lc250RXhpc3QgU3RhdGljQXNzZXJ0OyAvLyBUOjpOb3RFeGlzdGluZyBkb2Vzbid0IGV4aXN0IGF0IGFsbCEKfTsKCgp2b2lkIGYxKFN0YWNrPGNoYXI+KTsgLy8gTm8gaW5zdGFudGlhdGlvbiwgY29tcGlsZXMKCmNsYXNzIEV4ZXJjaXNlIHsKICAvL1N0YWNrPGRvdWJsZT4gJnJzZDsgLy8gTm8gaW5zdGFudGlhdGlvbiwgY29tcGlsZXMgKHJlZmVyZW5jZXMgZG9uJ3QgbmVlZCBpbnN0YW50aWF0aW9uLCBhcmUgc2ltaWxhciB0byBwb2ludGVycyBpbiB0aGlzKQoKICBTdGFjazxpbnQ+ICAgIHNpOyAvLyBJbnN0YW50aWF0aW9uISBEb2Vzbid0IGNvbXBpbGUhIQp9OwoKCmludCBtYWluKCl7CgogIFN0YWNrPGNoYXI+ICpzYzsgLy8gTm8gSW5zdGFudGlhdGlvbiwgdGhpcyBjb21waWxlcyBzdWNjZXNzZnVsbHkgc2luY2UgYSBwb2ludGVyIGRvZXNuJ3QgbmVlZCBpbnN0YW50aWF0aW9uCgogIC8vZjEoKnNjKTsgLy8gSW5zdGFudGlhdGlvbiBvZiBjaGFyISBEb2Vzbid0IGNvbXBpbGUhIQoKICAvL2ludCBpT2JqID0gc2l6ZW9mKFN0YWNrPCBzdGQ6OnN0cmluZyA+KTsgLy8gSW5zdGFudGlhdGlvbiBvZiBzdGQ6OnN0cmluZywgZG9lc24ndCBjb21waWxlISEKCn0=
compilation info
prog.cpp: In instantiation of ‘class Stack<int>’:
prog.cpp:15:17: required from here
prog.cpp:6:39: error: ‘int’ is not a class, struct, or union type
typedef typename T::ThisDoesntExist StaticAssert; // T::NotExisting doesn't exist at all!
^
prog.cpp: In function ‘int main()’:
prog.cpp:21:16: warning: unused variable ‘sc’ [-Wunused-variable]
Stack<char> *sc; // No Instantiation, this compiles successfully since a pointer doesn't need instantiation
^
stdout