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.