64,662
社区成员
发帖
与我相关
我的任务
分享
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include "testPLUS.h"
int _tmain(int argc, _TCHAR* argv[])
{
volatile testPLUS * x; // 我需要一个 volatile 变量,可是声明为volatile后就报错了,不声明为volatile就没问题。
x = new testPLUS();
x->testBASE_a(); // 编译提示该行出错。
return 0;
}
//testBASE.h : 基类testBASE的 声明。
#pragma once
class testBASE
{
public:
testBASE();
virtual ~testBASE();
void testBASE_a();
};
//testBASE.h : 基类testBASE的 定义。
#include "stdafx.h"
#include "testBASE.h"
testBASE::testBASE()
{}
testBASE::~testBASE()
{}
void testBASE::testBASE_a()
{
return;
}
//testPLUS.h : 派生类testPLUS的 声明。
#pragma once
#include "testBASE.h"
class testPLUS :
public testBASE
{
public:
testPLUS();
~testPLUS();
};
//testPLUS.h : 派生类testPLUS的 定义。
#include "stdafx.h"
#include "testPLUS.h"
testPLUS::testPLUS()
{}
testPLUS::~testPLUS()
{}
编译的输出内容如下:
1>------ 已启动全部重新生成: 项目: ConsoleApplication1, 配置: Debug Win32 ------
1> stdafx.cpp
1> testPLUS.cpp
1> testBASE.cpp
1> ConsoleApplication1.cpp
1>c:\users\zzs\desktop\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C2662: “void testBASE::testBASE_a(void)”: 不能将“this”指针从“volatile testPLUS”转换为“testBASE &”
1> 转换丢失限定符
1> 正在生成代码...
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========