Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@manish-r2Hoep • Aug 5, 2010
How can we help? -
@pensu-8tNeGU • Aug 5, 2010
What kind of help exactly do you want?.......specify... -
@bca-girl-wzX9cA • Aug 6, 2010
Hi,
I am confused about "classes in C++". Please provide me notes of this topic or expain it to me. In wait of your reply.......... -
@manish-r2Hoep • Aug 6, 2010
Classes are soul of oops
its a large topic no one can explain in single post
please explain where are you getting confused? -
@bca-girl-wzX9cA • Aug 6, 2010
I need a program that illustrates "structure and classes". -
@pensu-8tNeGU • Aug 6, 2010
Check the following link. It may help you.
#-Link-Snipped-# -
@sushant005-tyt4WK • Aug 6, 2010
Let me explain you what is class?
In the simple sense we can say that class is a logical concept.It means that it has no existence without an object.
Now what is a object?
Object is physical concept or we can say that it is the instance of class or we can say that object has a state and behavior.
As class is logical concept it does not allocate any memory unless an object is created.
Class is same as the structure or you can say that it is the next step to the structure and build with some extra features than structure.
struct book
{
char name;
float price;
char author;
}b;
If you consider the above program here structure are no going to take memory.It is just a form of structure data type struct book unless you do not create any structure variable i.e b it does not take any memory space.Like wise in class concept when we are create/ declare object then only it takes the memory space for the data members defined within the class.
The major difference between the structure and the class is that Structure is by default public and class is by default private.
You will better understand class with the concept of OBJECT.
If you have any doubt feel free to ask any question regarding this! -
@manish-r2Hoep • Aug 6, 2010
Nice explanation sushant,
one more difference to add
In case of classes data hiding is possible where as in case of structures data hiding is not possible which is one of the drawback of structureS
Here data hiding means "The object know only about data that it needs to know" -
@sushant005-tyt4WK • Aug 7, 2010
One more difference and i think this difference clear idea about the class and the structure.
Class is logical concept where as structure is a physical concept.
Here is the program clears the idea about structure,
#include<iostream.h>
Here in the above program the struct is defined outside the main().And one thing to notice is that there is no struct variable declared but it shows the size of the struct node.It proves that it is a physical concept since without declaring the structure variable it take memory space.But that is not in the case of class is totally logical unless we create an object it is no going to take any memory space.
struct node
{
int a;
};
void main()
{
cout<<"output="<<sizeof (struct node);
}
here the code for the class,
#include<iostream.h>
#include<conio.h>
class A
{
public:
int a;
};
void main()
{
A a;/*here object is created and this allows to take the memory space for the class variable.
unless you create object class has no existence*/
cout<<"Size of A="<<sizeof (a);
getch();
} -
@morningdot-6Xuj4M • Aug 7, 2010
Nice explanation sus.
Looks like you also gonne cody now. -
@praveenkumar-66Ze92 • May 17, 2011