+ Reply to Thread
Results 1 to 2 of 2

Thread: What is "virtual used for static member function" error in C++?

  1. #1

    What is "virtual used for static member function" error in C++?

    I created below class and got this error:

    Code:
    class CMyClass
    {
    	static int m_nCount ;
    public:
    	static virtual void DoSomething() {}
    } ;
    Error:
    error C2576: 'DoSomething' : virtual used for static member function

    What is the reason? Why it does not compile?

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    No, you cannot create a class method having both 'static' and 'virtual' keyword.

    'virtual' keyword is bound to a class object while 'static' is not bound to a class object.

    So the error your are getting is correct and you should either remove 'static' or 'virtual' from the method declaration.

    Thanks.

+ Reply to Thread

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