Diagnostic 1757: virtual entity-kind

Cause:

The compiler issues this message if a member function of an unamed namespace that is not a pure virtual function, is not defined. A member of an unnamed namespace can never be defined externally in another file, so if it is not pure virtual and not defined in the current file and is used, either explicitly by a routine call or implicitly by being a virtual function table entry then you will never get the program to link successfully.  For example:



namespace {
class C {
public:
virtual void f();  // f is only declared, but not defined
};
void foo() { C c; c.f(); }
} 

>icl - t.cpp
Intel® C++ Intel® 64 Compiler XE for applications running on Intel® 64, Ve
rsion 12.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

t.cpp
t.cpp(4): error #1757: virtual function "<unnamed>::C::f" was not defined (and c
annot be defined elsewhere because it is a member of an unnamed namespace)
virtual void f();  // f is only declared, but not defined
^

Resolution:

Define the function if it is not a virtual function:

namespace {
class C {
public:
virtual void f() {};   
};
void foo() { C c; c.f(); }
}

>icl -c t.cpp
Intel® C++ Intel® 64 Compiler XE for applications running on Intel® 64, Ve
rsion 12.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

t.cpp

Another possible solution is to move the class outside of the unnamed namespcae and define it in another source file which is eventually linked in so the definition is resolved.

For more complete information about compiler optimizations, see our Optimization Notice.