1.
키워드 : 제너릭,형, 템플릿,c++,c,java
2.
http://blog.naver.com/seektruthyb?Redirect=Log&logNo=150114746546
3.
이건 template선언 후 포인터로 할당하여 사용한 것.
#include <stdio.h> #include <string.h> template <class T> class Temp { private: T data; public: void setData(T data) { this->data = data; } T getData() { return this->data; } }; int main(int argc, char* argvp[]) { char *pChar; pChar = new char[10]; strncpy(pChar, "hello", 10); pChar[5] = '\0'; Temp<char *> *charT = new Temp<char *>(); charT->setData(pChar); printf("%s\n", charT->getData()); delete charT; delete pChar; return 0; } |
이건 일반 선언해서 사용한 것
#include <stdio.h> #include <string.h> template <class T> class Temp { private: T data; public: void setData(T data) { this->data = data; } T getData() { return this->data; } }; int main(int argc, char* argvp[]) { char *pChar; pChar = new char[10]; strncpy(pChar, "hello", 10); pChar[5] = '\0'; Temp<char *> charT; charT.setData(pChar); printf("%s\n", charT.getData()); delete pChar; return 0; } |