DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Static virtual

  1. #1
    Join Date
    Dec 2003
    Location
    London
    Posts
    10

    Static virtual

    Hello,

    Can a static member function be virtual?

    I believe not. But can someone please explain why ?

    Thanks,

    Imanuel.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    of course, it can not. The reason is simple: a virtual member function must take an implicit 'this' argument so that the compiler and runtime libraries can resolve the call properly. However, since static member functions don't take a this argument, they can't be virtual. Notice that you can call a static member without even instantiating an object:

    struct A
    {
    static f();
    };

    A::f(); //fine

    As a rule, virtual member functions are called for a specific OBJECT. Static member functions are called for a CLASS and therefore can only access static data members.
    Last edited by Danny; 02-21-2004 at 05:18 PM.
    Danny Kalev

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links