Results 1 to 6 of 6

Thread: Virtual inline in C++

  1. #1
    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?

  2. #2
    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.

  3. #3
    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?

  4. #4
    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.

  5. #5
    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?

  6. #6
    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();

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,867,350.58120 seconds with 17 queries