Get function speed issues...

Started by
12 comments, last by Drythe 20 years, 4 months ago
quote:Original post by Drythe
what is ''inlined''?

An inline function just means that the actual function code is "copy and pasted" every time the function is called, instead of having a function call set up.

It executes faster, but takes up more space in the cache.

Also, no one else has pointed this out, but your GetNumParts() function actually is inlined. By including the function body inside the class (not just the declaration) you are instructing the compiler to make it inline. Actually, it''s more of a suggestion than an instruction, as the compiler is free to ignore it, but generally it will be inlined in release builds.
Advertisement
If you don''t do anything in both the get and set function then just make that variable public.

--------
"Hey, what about those baggy pants you kids are wearin'' these days? Aren''t they hip and cool and poppin'' fresh?"-Peter Griffin
"Everytime I see an M followed by a dollar sign I just say "oh god" and go to the next post."-Neurokaotix
the D programming language
Your professor is wrong, over use of get and set is as much a violation of data encapsualtion as public members. Classes should encapsulate both data and function, if this advice is followed you will find there is little need for multiple get and set methods.

Wizza Wuzza?
quote:Original post by brassfish89
If you don''t do anything in both the get and set function then just make that variable public.


What if he needs to make the get and set function do something later on?

Or what if he chooses to store the parts differently (perhaps to optimize the program) and has to do some complicated math to find the number of parts? It''s not likely but it could happen.

Also, using get and set functions help avoid errors like this:

CProp prop;if (prop.GetNumParts() = 25)    OmfgError();

This topic is closed to new replies.

Advertisement