Help me about " template"
-
How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....
ubri
-
How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....
ubri
ubriela wrote:
#define string char *
Besides the fact that you are posting this in the wrong forum (this should be on the Visual C++/MFC board)... What's the error you are getting? I can't read your code without the angle brackets on your template code... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
How can I use the word string as a data type, like int? C++ does not support it? ? #define string char * ????? // some time it is wrong Suppose that I have a header file for a template class: dummy.h #ifndef DUMMY_H_ #define DUMMY_H_ // phototype template class dummy { dummy(); public: void read(); // void get_value(T&); private: T value; } // Implimentation ....... template void dummy::read() { cin>>value; } ....... #endif // test #define string char * main() { dummy name; // object name name.read(); // -> an error occurs ....... } Why is that? if I replace string by int dummy name; name.read() // NO PROBLEM I knew my fault.... cin>>name can't be used for char * (pointer) but I want to use string as a data type, so that I can declare: dummy name; Can you have me? thanks a lot....
ubri
It seems you want to use of templates but can you write fully template code and does your question on the C++/CLI?