Please give me as detailed anwser as you can??
What is the difference between C++ struct and C++ class?
I popped your question into Google. Guess what I found? THE ANSWER!!!
http://www.google.com/search?q=What+is+t...
"The only difference between structs and classes in C++ is that the members of a struct have public visibility by default, and the members of a class have private visibility by default."
Reply:Josh is absolutely right though he was voted down. There is big difference between classic C stucts and C++ classes, but the only difference when considering only C++ stucts and class is the visibility.
Reply:A struct just holds data. A class can hold data and contain functions to perform specific operations.
struct Numbers
{
int number1;
int number2;
}
class NumbersClass
{
int number1;
int number2;
public double GetAverage()
{
return (number1 + number2) / 2;
}
}
Reply:Structs in c can only use member variables and not member functions. Also, for a structure, all members of the structure are public access, meaning any function or variable can access the data inside. A C++ class however can hold both member variables and functions, and can protect its variable so that they can only be accessed by objects of that class. The greatest difference, however, comes from the fact that C++ classes can be inherited, so that one class can be general, and then more classes can be derived from that one class, and still share the same members as the first class.
daylily
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment