Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-12-2008
Member
 
Join Date: May 2008
Posts: 923
Virtual inline in C++

Is it possible to declare a virtual inline in C++? Does this poses a problem to the compilation and/or performance when the call for a virtual inline function is from a secondary purpose?
Reply With Quote
  #2  
Old 27-12-2008
Member
 
Join Date: Feb 2008
Posts: 194
Re: Virtual inline in C++

Quote:
Originally Posted by Jacek View Post
Is it possible to declare a virtual inline in C++?
Yes

Quote:
Originally Posted by Jacek View Post
Does this poses a problem to the compilation and/or performance when the call for a virtual inline function is from a secondary purpose?
No, it does not poses any problem.
Reply With Quote
  #3  
Old 27-12-2008
Member
 
Join Date: May 2008
Posts: 923
Re: Virtual inline in C++

What surprises me is that I thought during the compilation, the compiler does not know whether it is the type of object that calls the declared virtual (ie: depending on the parent class or function Class) and thus may not be able to inline code. Am I wrong?
Reply With Quote
  #4  
Old 27-12-2008
Member
 
Join Date: Feb 2008
Posts: 194
Re: Virtual inline in C++

No. It is quite rightly. But nothing prevents you declare virtual inline and nothing prevents a compiler to inline a call to a virtual function if he knows to resolve statically.
Reply With Quote
  #5  
Old 27-12-2008
Member
 
Join Date: May 2008
Posts: 923
Re: Virtual inline in C++

Here is what I could have a sample code, which highlights the call for a virtual inline from a subclass that the compiler knows to solve statically:

Code:
class A
{
virtual inline f() {...} 
}; 
class B: public A 
{
virtual inline f() {...} 
}; 
main () 
{
A * a; 
a = new B(); 
a -> f(); 
}
In this case the compiler can not inline a-> f () a priori as I understand it, but in which case it may do as you pointed out to me?
Reply With Quote
  #6  
Old 27-12-2008
Member
 
Join Date: Feb 2008
Posts: 194
Re: Virtual inline in C++

In a static:

Code:
virtual void B::f() { A::f(); }
// Or
B b;
b.f();
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Virtual inline in C++"
Thread Thread Starter Forum Replies Last Post
Advantages of Inline Function Sonam Goenka Software Development 4 08-02-2010 11:07 AM
Don't know about an inline class Bottlenecked Software Development 5 25-01-2010 09:57 AM
What is the use of inline function Jabeen Software Development 3 19-11-2009 12:22 PM
Problem with static and inline in C++ Sujit15 Software Development 3 06-05-2009 01:15 PM
migrate Hyper-V virtual machine to virtual server/virtual PC 2007 Larry Scott Windows Server Help 1 18-03-2008 03:32 AM


All times are GMT +5.5. The time now is 02:12 PM.