Different B/W CLASSES & STRUCTUR in C\C++

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

Different B/W CLASSES & STRUCTUR in C\C++

Postby mani » Thu Apr 21, 2005 12:55 am

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
mani
Lance Naik
 
Posts: 33
Joined: Tue Aug 10, 2004 1:51 pm
Yahoo Messenger: muhammadabdullahusman@yahoo.com
Location: Islamabad

Postby outstream » Thu Apr 21, 2005 1:16 am

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
outstream
Naib Subedar
 
Posts: 322
Joined: Wed Sep 24, 2003 10:04 pm
Location: islamabad

Postby saquib_javed » Thu Apr 21, 2005 3:54 pm

Salam,

Please check for Object Oriented is. 8)

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. ;)
saquib_javed
Naib Subedar
 
Posts: 344
Joined: Sat Apr 10, 2004 9:07 pm
Website: http://www17.brinkster.com/saquibjaved
Location: Karachi

Re: Different B/W CLASSES & STRUCTUR in C\C++

Postby lambda » Fri Apr 22, 2005 3:34 am

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


is this a homework question?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

struct

Postby soni » Sun Apr 24, 2005 12:39 pm

structures do allow inheritance....

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);

}



struct{
//default member access....
public:
};

class{
//default member access....
private:
};
Please do not open M$Windoze.
soni
Naik
 
Posts: 70
Joined: Sat Oct 04, 2003 1:44 pm
Website: http://www.cyberian.pk
Location: Karachi

Re: struct

Postby lambda » Mon Apr 25, 2005 12:51 pm

soni wrote:struct{
//default member access....
public:
};

class{
//default member access....
private:
};


that's correct -- soni wins.
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Re: Different B/W CLASSES & STRUCTUR in C\C++

Postby salmankhilji » Wed May 04, 2005 9:30 pm

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


In C++, struct and class is EXACTLY the same semantically. Inheritance and polymorphism work EXACTLY the same on both.

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
salmankhilji
Cadet
 
Posts: 4
Joined: Tue Jan 27, 2004 7:38 am

Postby ishtiaq ahmed » Thu Sep 29, 2005 3:37 am

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.
ishtiaq ahmed
Naik
 
Posts: 50
Joined: Thu Dec 23, 2004 8:15 pm
Location: lahore

Postby lambda » Thu Sep 29, 2005 1:58 pm

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.

let's use your method of reasoning in another matter, shall we?

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.


does that tell you what a train is?


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".
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Hola

Postby soni » Thu Sep 29, 2005 2:08 pm

Brothers donot waste your time in arguments, do the real thing, the OOP dance and chill..... :)
Please do not open M$Windoze.
soni
Naik
 
Posts: 70
Joined: Sat Oct 04, 2003 1:44 pm
Website: http://www.cyberian.pk
Location: Karachi


Return to “%s” Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron