C++/CLI类函数重写规则的一些例子
来源:互联网 发布:apache cacti安装配置 编辑:程序博客网 时间:2024/05/17 22:54
- /*
- (C) EnzoYang 2008
- Filename : testoverride.cpp
- Compiler : Visual C++ 9.0 / Visual Studio 2008
- Description : test about C++/CLI override
- Release : 11/30/2008 1.0
- */
- #include "stdafx.h"
- using namespace System;
- ref class B abstract
- {
- public:
- virtual void fun() abstract;
- virtual void f() abstract;
- virtual void error() {System::Console::WriteLine(L"myerror");};
- };
- interface class IB
- {
- void fun();
- };
- ref class D: B, IB
- {
- public:
- virtual void fun1() = B::fun //重写了B::fun
- {
- System::Console::WriteLine(L"b::fun");
- };
- virtual void fun2() = IB::fun //重写了IB::fun
- {
- System::Console::WriteLine(L"ib::fun");
- };
- virtual void f() override
- {
- System::Console::WriteLine(L"f");
- };
- virtual void fun() new //与上面的重写无冲突
- {
- System::Console::WriteLine(L"hello");
- };
- virtual void error() new = B::error //正确 但是error依然是重写了B::error
- {
- System::Console::WriteLine(L"error");
- };
- //***1***virtual void error() new { System::Console::WriteLine(L"error");};
- //正确 error只是隐藏了 B::error
- //virtual void error() override = B::error { System::Console::WriteLine(L"error");};
- //错误 ,error 不能被多次重写,这里显式和隐式各一次了
- //virtual void error() override = B::error { System::Console::WriteLine(L"error");};
- //错误同上
- };
- int main(array<System::String ^> ^args)
- {
- //String sstr;
- D^ d = gcnew D;
- d->fun();
- d->fun1();
- d->fun2();
- d->f();
- B^ b = d;
- b->fun();
- b->error(); // 这里的输出是error 如果用注释中的***1***那条语句的话输出时myerror
- IB^ ib = d;
- ib->fun();
- String ^str = Console::ReadLine();
- return 0;
- }
输出结果
hello
b::fun
ib::fun
f
b::fun
error
ib::fun
- C++/CLI类函数重写规则的一些例子
- C++/CLI接口中函数重写的一些规则的例子
- C++/CLI的函数覆盖
- C++/CLI(七):类函数
- 学习C++/CLI的一些资源
- 学习C++/CLI的一些资源
- Intelligencia.UrlRewriter.dll重写URL的规则例子
- C++/CLI的静态构造函数
- C++/CLI(六):函数
- 【继承与多态】C++:继承中的赋值兼容规则,子类的成员函数,虚函数(重写),多态
- 【继承与多态】C++:继承中的赋值兼容规则,子类的成员函数,虚函数(重写),多态
- 函数重载(overload)和函数重写(override)的基本规则
- 重写虚函数的一些感悟
- 一些函数使用的例子
- C++/CLI编程一些基本概念
- 重写父类方法的规则
- 方法重写的规则
- .htaccess -------------的重写规则,
- 去鸟巢看奥运时的照片。
- STL:map与hash_map
- 十人看了九人得道!
- GetMessage与PeekMessage(16位windows程序)
- 在google上排在前3页的programmer站点排名
- C++/CLI类函数重写规则的一些例子
- 看20081130火箭VS马刺比赛有感
- 中国市场营销资格证书
- 自制CCTV在线直播的实现
- vb 正则表达式1
- vb 正则表达式2
- 'foreground_regions' 问题
- C++/CLI接口中函数重写的一些规则的例子
- vb word插件