fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. template <typename T> class Stack {
  6. typedef typename T::ThisDoesntExist StaticAssert; // T::NotExisting doesn't exist at all!
  7. };
  8.  
  9.  
  10. void f1(Stack<char>); // No instantiation, compiles
  11.  
  12. class Exercise {
  13. //Stack<double> &rsd; // No instantiation, compiles (references don't need instantiation, are similar to pointers in this)
  14.  
  15. Stack<int> si; // Instantiation! Doesn't compile!!
  16. };
  17.  
  18.  
  19. int main(){
  20.  
  21. Stack<char> *sc; // No Instantiation, this compiles successfully since a pointer doesn't need instantiation
  22.  
  23. //f1(*sc); // Instantiation of char! Doesn't compile!!
  24.  
  25. //int iObj = sizeof(Stack< std::string >); // Instantiation of std::string, doesn't compile!!
  26.  
  27. }
Compilation error #stdin compilation error #stdout 0s 3336KB
stdin
Standard input is empty
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
Standard output is empty