473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Member vs Non member function

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
2 4919

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
3
by: Roy Yao | last post by:
Hello, I need to pass a pointer to a callback function to the lower level modules. But the function is thought to be a virtual member one. How can I get the real address of the virtual...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
7
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
13
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member...
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.