These three points all relate to the same "empty function" question:
- How much processing time is wasted when calling an empty function?
- Would it make a huge impact to call 100, or even 1000 empty functions?
- What if these empty functions required arguments?
Important edit Is calling an empty virtual function the same?
Edit SO basically you are all saying that in most cases the compiler will optimize this out.
But now I'm curious as this still applies to the question. What if there's a situation like so, where it is not known at compile time when an empty function will be called? Will it immediately go to the stack then exit?
class base{
public:
virtual void method() = 0;
};
class derived1: public base{
public:
void method() { }
};
class derived2: public base{
public:
void method(){ std::cout << " done something "; }
};
int main()
{
derived1 D1;
derived2 D2;
base* array[] = { &D1, &D2 };
for( int i = 0; i < 1000; i ++)
{
array[0]->method();// nothing
array[1]->method();// Something
}
return 0;
}