[ create a new paste ] login | about

Link: http://codepad.org/ygjfLnZo    [ raw code | output | fork ]

C++, pasted on Jul 26:
#include <iostream>

template <class T>
class comprehendTemplate {
  private:
        T val;
  public:
        comprehendTemplate(T num);
        
        T getVal();
};

comprehendTemplate::comprehendTemplate(T num) : 
        val(num) { 
        std::cout << "val " << val << std::endl;
}

T comprehendTemplate::getVal() 
{
   return val;
}

int main()
{
    comprehendTemplate <int>ct(9);
    comprehendTemplate <std::string>ct2("Hello");
    std::cout << "getVal of ct " << ct.getVal() << std::endl;
    std::cout << "getVal of ct2 " << ct2.getVal() << std::endl;
    
    return 0;
}


Output:
1
2
Line 13: error: 'template<class T> class comprehendTemplate' used without template parameters
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: