//关于 return 一个 void 的问题?
songk 2002-04-29 07:49:22 //下边的代码通过 Solaris 6的 gcc version 2.95.3 20010315 (release) 编译没有报错。
//但是 Win2K 的 VC++6 就报错,为什么 B::vf()返回一个void还会报错?
//但是我发现上边的 gcc 对全局函数的处理是和 VC6 类似报错的,但对类中的就不报错,可以正常运行。
//为什么?
//#include "stdafx.h"//此行仅于VC++6中
#include <iostream>
using namespace std;
class B{
public:
virtual void f() =0;
};
class D:public B{
public:
void f(){ return vf(); }
void vf() { cout<<"D::vf()"<<endl;}
};
main()
{
B* p=new D;
p->f();
}
//VC6中的报错信息
//--------------------Configuration: t01 - Win32 Debug--------------------
//Compiling...
//t01.cpp
//D:\_MyVC\__TEST\_MyTests\t01\t01.cpp(17) : error C2562: 'f' : 'void' function returning a value
// D:\_MyVC\__TEST\_MyTests\t01\t01.cpp(17) : see declaration of 'f'
//Error executing cl.exe.
//
//t01.exe - 1 error(s), 0 warning(s)