HelpDifferenct Between (Class) and (Struct) ???

Posts 1–12 of 12 · Page 1 of 1
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.
Just what @Void said, probably you'll prefer using structs as they're public by default and you don't have to type it every time (what u probably do)
Quote Originally Posted by Cernunnos View Post
Just what @Void said, probably you'll prefer using structs as they're public by default and you don't have to type it every time (what u probably do)
That makes no sense. You should always say if it public or private... always. It is good practice. (This is the reason why I didnt bother posting that difference)
Quote Originally Posted by 'Bruno View Post


That makes no sense. You should always say if it public or private... always. It is good practice. (This is the reason why I didnt bother posting that difference)
What I'm trying to say is :
Code:
 

class MyClass {
public:
MyClass(int a, double b, float c, char *d); 
int a;
double b;
float c;
char* d;
}
So, if isn't supposed to anything be private why use class instead of struct ?
Quote Originally Posted by Cernunnos View Post
What I'm trying to say is :
Code:
 

class MyClass {
public:
MyClass(int a, double b, float c, char *d); 
int a;
double b;
float c;
char* d;
}
So, if isn't supposed to anything be private why use class instead of struct ?
I think classes can hold structures and functions as well. I don't work with classes or structures much myself so I wouldn't know fully.
struct and class are equivalent, except for default access (struct - public) (class - private)
In C++ there's no difference really (Except public/private defaults). I heard in C it had memory differences
Quote Originally Posted by Kenshin13 View Post
In C++ there's no difference really (Except public/private defaults). I heard in C it had memory differences
There is no classes in C. C is not Object oriented
Quote Originally Posted by 'Bruno View Post


There is no classes in C. C is not Object oriented
Well shit, I read it wrong. Just realized. Then I meant C++
@'Bruno @Void @Cernunnos @dream90 @[MPGH]Kenshin13 @lol98lol98
lolz sorry just after posting this thread i figured out that just like void said, classes are private by default and strukt are public by default..
so i dint open this thread again i even forgot that i posted one
Thx all i apretiate ur help guys
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us