Solved

oop in C

Posted on 2004-08-19
9
231 Views
Last Modified: 2013-12-14

if OOP is possible in C, why was C++ invented, when it could have simply been a third party
library that some company made for 'C'

does c++ do things that are just not possible in 'C' without a writing a large amount
of code, that would not otherwise be required with c++ ?

0
Comment
Question by:apakian
9 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11842279
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 11842285
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 11842307
0
 
LVL 11

Expert Comment

by:griessh
ID: 11842938
Hi ankuratvb,

>> third party library
because C++ is a superset of and not just a library. Polymorphism etc are part of the language and not only linkage.

>>c++ do things that are just not possible in 'C'
function overloading is not possible in C, C++ uses a concept called 'name mangling' to differentiate functions.

======
Werner
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:griessh
ID: 11842949
sorry, this was for apakian :-)
0
 
LVL 11

Accepted Solution

by:
avizit earned 100 total points
ID: 11843230
to add to it

you can implement classes as structures in C but you really cant have the protection afforded by private and public members etc

0
 
LVL 22

Expert Comment

by:grg99
ID: 11845448
OOP is *possible* in C, but it requires great discipline and many tricky macros.

Perhaps you were misled when you read somewhere that early C++ compilers just translated C++ into C.  That is a non-trivial transformation, not one you'd enjoy doing by hand.

0
 

Expert Comment

by:lebuihung
ID: 11867517
i think there are something we can do easily in c++ but not in c:

1. inheritace.
2. operator overload. For example: operator >> ( ....)

I think those 2 things are very important point of OOP, but C doesnt support or just very fex.

Hope that will help.
0
 
LVL 4

Expert Comment

by:pankajtiwary
ID: 11868118
Actually after C, the next step in the path of OOP was c with classes. It was nothing but a preprocessor sort of stuff which converts a "c with classes" code into a pure C code. It involved introduction of classes and inheritence too if I remember correct. This "c with classes" language was then used to go further and after a lot of efforts, it came out to be C++ what we see today.

The moral of the story is I don't see anything which can be done in C++ and not in C. What it just takes is a lot of investment in terms of time. What C++ provides is a framework for supporting user defined datatypes in exactly the same way it supports built-in types. This make programming more easy and maintainable.

Even you can imlement vrtual functions and inheritance and other stuffs in C but you never want to do so because its no use reinventing the wheel.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now