Archived

This topic is now archived and is closed to further replies.

Oscar A

C++ struct and class

Recommended Posts

I have a question about struct contra class in C++. What i know struct and class almost have the same syntax. My question is what is the differens and when should struct be better then a class. Maybe it is like C# where struct is a value type and you could pass it to a method as a value but a class is a reference typ and you could only pass it to a method as a reference. But in C++ you could pass a class by value to ??? The struct struct Hello { char msg[25]; Hello(char *pMsg) { if(pMsg != NULL) strcpy(msg, pMsg); } // Method void setName(char *pMsg) { if(pMsg != NULL) strcpy(msg, pMsg); } }; The class class Hello { private: char msg[25]; public: Hello(char *pMsg) { strcpy(msg, pMsg); } // Method void setName(char *pMsg) { if(pMsg != NULL) strcpy(msg, pMsg); } }; A would be happy for a answer from some expert out in the cyberspace :-) Happy Hacking. Don't forget to eat and sleep [edited by - Oscar A on March 17, 2003 4:34:17 PM]

Share this post


Link to post
Share on other sites