Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Possibility

What are the advans/disadvans of using class member functions vs normal functions?

This topic is 6688 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 just learned how to use classes and their member functions, and I was just wondering if they are slower or faster then normal functions and if they have other advantages, and what about class arrays? for example: class TIME{ public: ..... private: ..... } time[5]; are the member functions in there gonna be just as fast as if I were to use a struct and just write my own normal functions? Possibility

Share this post


Link to post
Share on other sites
Advertisement
There might be a slight performance difference due to implementation details, but there is no reason why a member function should be any faster/slower than a normal function.

Certainly if there is a difference, it will not be very significant, at most the cost of pushing a few more things onto the stack in the function call.

#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

Share this post


Link to post
Share on other sites
As long as you don''t use virtual member methods and/or virtual inheritance, member methods are as fast as normal C functions.

The only difference is that member methods internally have one (implicit) parameter: the this pointer. The value of the this pointer is pushed to the stack prior to calling the member function.

int A::b() { /* ... */; return 0; }
is roughly implemented as
int A__b(const A *this) { /* ... */; return 0; }

However, if you''d try to achieve encapsulation in C, you''d probably end up doing it the same way.

Erik

Share this post


Link to post
Share on other sites
I agree - OO is the way to go. Many good things have caused slight performance hits but resulted in massive productivity improvements and algorithmic improvements.


#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

Share this post


Link to post
Share on other sites
Yup,
OO is shorthand for Object Oriented. (and OOP is Object Oriented Programming).

-Brian

Share this post


Link to post
Share on other sites
So what does Object oriented programming actually mean. I am fairly certain I already do that, but what is it precisely and why is SO good?

Possibility

Share this post


Link to post
Share on other sites
I have programmed in C++ for about 4 months now, and have pondered the exact same thing... anyone?

GO LEAFS GO!

Share this post


Link to post
Share on other sites
I have been programming in C++ for a few months now, and, although I have learnt and can understand Classes and OOP, I have never actually used them in a project, as I''ve never really seen the need. I never did understand what the advantages/disadvantages were.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!