Jump to content
  • Advertisement
Sign in to follow this  
jakpandora

Are classes and objects OOP?

This topic is 5413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been wondering about this recently. are classes and objects part of OOP? How is that possible, if you can use classes and objects in C? could someone clarify this for me? thanks!

Share this post


Link to post
Share on other sites
Advertisement
Yes. In C, you only have structs, and you can't have member functions, or anything like virtual functions. Plain C structs can only contain data members.

Share this post


Link to post
Share on other sites
You can't use classes or "objects" in C. As Evil Steve said, C only has structs which can store data (so they're really only chunks of data, not real classes).

C++ introduces (true, native support for [rolleyes]) OOP and classes, there's no way to use them in C (without nasty hacks).

Share this post


Link to post
Share on other sites
Quote:
Original post by Ra
C++ introduces OOP and classes, there's no way to use them in C.


Thats not quite correct. If you look at some commercial game C source (I am speaking of Sin/Q2/Q3), you will notice a suprising amount of objects. How do you use a simple form of objects in C? Simply: you give the structs datamembers of function pointer type. DANG! You have objects. You can even hide a structs data if you really want.

You can do a lot of OOP with pure C and... well... OOP.

Thermo/Konfu

PS: of course, your answer to jakpandora still holds true :)

Share this post


Link to post
Share on other sites
Alright, maybe just "OOP" wasn't the correct term there, but true (native support for) OOP isn't available in C.

Share this post


Link to post
Share on other sites
There's no significant difference between
void foo(A *, int param);
and
void A::foo(int param);

So, the C struct can act much as the C++ class. Inheritance and virtual functions however, are much more complex, and require use of the union, function pointers, and the parent class must have a list of all of its children. Oh well.

Share this post


Link to post
Share on other sites
After all, what makes a "member function" a "member" of a class is the this pointer at the start of its parameter list.
C++ only happens to hide this pointer (for good reasons of course).

Thermo

Share this post


Link to post
Share on other sites
Quote:
If you look at some commercial game C source (I am speaking of Sin/Q2/Q3)


I was actually looking at the quake 1 source, and saw those structs.I thought they were objects however, and got confused, so I decided to ask here. anyways, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!