CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    Is a non-virtual member function without an implementation legal ?

    I noticed something strange in VC 6. Take the following code :

    PHP Code:
    class CTest {
    public:
        
    CTest()
        {
        }

        
    void CalledFunc();
        
    void NotCalledFunc();
    };

    void CTest::CalledFunc()
    {
    }

    int main()
    {
        
    CTest *ptst = new CTest;

        
    ptst->CalledFunc();
        
    delete ptst;
        return 
    0;

    This compiles and runs correctly, even though I've never provided an implementation of NotCalledFunc. Should it not give me at least an unresolved external error during compilation, or is this behaviour specified like this in the C++ standard ?

    The reason why this happens in VC seems obvious. The compiler automatically strips away functions which are never called, so that the implementation of NotCalledFunc is never actually needed.
    Last edited by Yves M; September 5th, 2002 at 01:13 PM.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured