Which is faster ?View more random threads:
- why we use pointers or reference except using real name of...
- can we define same functions for the two or more different...
- char s1[] = "example"; char s2[20] = "another example"...
- Explain overridig with example 2011
- how many malloc ,calloc and realloc take arguments in c++
- CS201 - Introduction to Programming important blanks for...
- program Output in C++ 2012
- Programme Not Run in C++ giving erros 2011
- is there anything else like winzip wizard to run the...
- using namespace std;"in the code can we compile the...
A. Call 1000 times a virtual function OR
B. call 1000 times a normal function trough a function pointer.
For example:
A.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Base
{
public: virtual void myfunc() = 0;
};
class Child: public Base
{
public: void myfunc(){...}; //overriding the base class function
}
int main()
{
Child myclass;
call myclass.myfunc() 1000 times
}
B.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class SomeClass
{
public: void myfunc(){ ... }
};
int main()
{
SomeClass myclass;
void (*foo)();
foo = &myclass.myfunc;
call foo() 1000 times
}
What do You guys think which one would perform better ?
Assume that the compiler will surely not be able decide the class type in the virtual function case (A). And also the functions are quite complex and big.
Sponsored Links
Urgent call: 03455242488. | Virtual University Assignments
Virtual University GDBs | Virtual University Papers | Vu Projects | Vu Handouts
About Expert
There are currently 1 users browsing this thread. (0 members and 1 guests)