Hi 2 All,
i want 2 know that what is the major different in Structur and Class in C\C++ programming language. what r the Advantages and Disadvantages of then
Different B/W CLASSES & STRUCTUR in C\C++
one of the biggest difference just came to mind is..classes support inheritence, structures dont.. is that a homework question by the way?
Testing?What's that? If it compiles, its good, if it boots up it is perfect.
----------------------------------------------------
Imran
Registered Linux User # 334322
----------------------------------------------------
Imran
Registered Linux User # 334322
-
- Naib Subedar
- Posts: 344
- Joined: Sat Apr 10, 2004 9:07 pm
- Location: Karachi
- Contact:
Salam,
Please check for Object Oriented is.
Do refer to book C How to program Deitel & Deitel
http://www.deitel.com/
http://webopedia.com/TERM/o/object_oriented.html
ThanX
Please check for Object Oriented is.
Do refer to book C How to program Deitel & Deitel
http://www.deitel.com/
http://webopedia.com/TERM/o/object_oriented.html
ThanX
Use Linux and feel Free.
OR
Feel free to use Linux.
OR
Feel free to use Linux.
Re: Different B/W CLASSES & STRUCTUR in C\C++
is this a homework question?mani wrote:i want 2 know that what is the major different in Structur and Class in C\C++ programming language. what r the Advantages and Disadvantages of then
struct
structures do allow inheritance....
struct{
//default member access....
public:
};
class{
//default member access....
private:
};
Code: Select all
#include <stdio.h>
struct father{
father(){
printf("In the father....\n");
}
int scalar;
};
struct child : father{
child(){
printf("In the child....\n");
this->scalar = 20;
}
};
main(void){
struct child obj;
printf("%d\n", obj.scalar);
}
//default member access....
public:
};
class{
//default member access....
private:
};
Please do not open M$Windoze.
Re: struct
that's correct -- soni wins.soni wrote:struct{
//default member access....
public:
};
class{
//default member access....
private:
};
-
- Cadet
- Posts: 4
- Joined: Tue Jan 27, 2004 7:38 am
Re: Different B/W CLASSES & STRUCTUR in C\C++
In C++, struct and class is EXACTLY the same semantically. Inheritance and polymorphism work EXACTLY the same on both.mani wrote:Hi 2 All,
i want 2 know that what is the major different in Structur and Class in C\C++ programming language. what r the Advantages and Disadvantages of then
The only difference is what is private and public be default. In a struct everything is public by default. However, there is nothing to stop you from specifying public: to make everything public. In a class, everything is private by default. However you can specify private: to achieve the same effect.
Some older compilers allow interchaning the keyword struct and class. i.e you can forward declare something to be struct and later define the thing as a class instead. These compilers, noticeably VC++ will generate a warning only. Other compilers simply will refuse to do so.
HTH,
Salman
-
- Naik
- Posts: 50
- Joined: Thu Dec 23, 2004 8:15 pm
- Location: lahore
actually brother u should have asked question like this, the difference between object oriented approach and the structural.
so basic difference between them is that oo approach is like a human eye that it is a object which contain attributes like ball and so on . and its function to. as in case of class object.
while in case of structural approach its not the case.
that is the very basic difference between them. i liked this example very much when i read that first time. so i am sharing it with u.
so basic difference between them is that oo approach is like a human eye that it is a object which contain attributes like ball and so on . and its function to. as in case of class object.
while in case of structural approach its not the case.
that is the very basic difference between them. i liked this example very much when i read that first time. so i am sharing it with u.
let's use your method of reasoning in another matter, shall we?ishtiaq ahmed wrote:so basic difference between them is that oo approach is like a human eye that it is a object which contain attributes like ball and so on . and its function to. as in case of class object.
while in case of structural approach its not the case.
does that tell you what a train is?q. what is the difference between cars and trains?
a. the basic difference is that cars have four wheels, a driver's seat with a steering wheel, a gear shift, and two or three pedals. while in the case of a train, that is not the case.
anyway, your description is incorrect. the main difference between object-oriented programming and procedural programming is that in oop you put your code and the data used by that code in the same "place." in procedural programming, the code and data are not bound together as tightly as they are in oop.
however.
even that's not an accurate description, because in some languages, which are completely object oriented from the ground up, the code is still separate from the data. see this for a description of many things that are called "object-oriented".
Hola
Brothers donot waste your time in arguments, do the real thing, the OOP dance and chill.....
Please do not open M$Windoze.