By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

Member vs Non member function

P: n/a
Per
Hi!
Does it take longer time to initialize a class with many
member-functions
than one with fewer?
Will the sizeof (Some Class) return more bytes on a class with more
member-functions etc...
/p
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Per" <pe*********@gmail.com> wrote in message
news:f6**************************@posting.google.c om...
Hi!
Does it take longer time to initialize a class with many
member-functions
than one with fewer?
Will the sizeof (Some Class) return more bytes on a class with more
member-functions etc...
/p


No, it will not. This is all taken care of by the compiler - obviously
at compiletime. The size of your class should not increase.
Deciding whether a function should be a member is usually a design
decision and has nothing to do with optimisations.

Usually, unless there's a very good reason to make it a member
function [Example:
- you need to access private members that you can't otherwise
- you need to override a virtual function
- it can't be implemented using the current class' public interface
- it is an operator that requiers to be a member], you should probably
not make it a member. It is better to have as simple as possible (but
not simpler) interfaces to keep things clear.

Vladimir Ciobanu.
Jul 22 '05 #2

P: n/a

"Per" <pe*********@gmail.com> wrote in message
news:f6**************************@posting.google.c om...
Hi!
Does it take longer time to initialize a class
A class cannot be initialized. A class specifies a type.
An object of class (or any other) type can be intitialized.
with many
member-functions
than one with fewer?
The language does not specify at all how long
a particular construct takes to execute. This depends
entirely upon the implementation and the host platform.
But in practice, I would not expect any performance difference
between initializing an object of a type with no member functions
and one with many.
Will the sizeof (Some Class) return more bytes on a class with more
member-functions etc...


No, the count of member functions does not affect the value
returned by applying 'sizeof' to the type containing those
member functions. It will report a size at least equal to
(but often greater than) the sum of the sizes of its data
members. The minimum it will report is a size of 1, even
for an 'empty' class such as:

class X
{
};

sizeof(X); /* yields a value >=1 */
-Mike
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.