Differenct Between (Class) and (Struct) ???
Is there any difference between struct and class?
Like :
Code:
#include <iostream>
#include <ctime>
using namespace std;
class box{
private:
double height,length,width;
char label;
public:
double volume()
{
return height*width*length;
}
double SA()
{
return 2*height*width + 2*height*length + 2*length*width;
}
void Increment_Height(double x)
{
height += x;
}
double Get_Height()
{
return height;
}
};
int main()
{
srand(time(NULL));
box me;
system("pause");
return 0;
}
if i change class by strut, no difference occur, so is there any difference i dont know? sorry im still learning, but in the end of c++ .
People tend to use structs just as a simple data structure without functions, methods, etc.. Even tho you can use it just like a class.
There is a different there and there but nothing really major.
Pretty sure someone will jump in a give you a more detailed example and explanation...
structs' members are public by default while a class' members are private by default. i bet you didn't think it was that simple.
struct and class are equivalent, except for default access (struct - public) (class - private)