C++/CLI接口中函数重写的一些规则的例子
来源:互联网 发布:淘宝网安全控件下载 编辑:程序博客网 时间:2024/05/18 02:42
- /*
- (C) EnzoYang 2008
- Filename : testIterface.cpp
- Compiler : Visual C++ 9.0 / Visual Studio 2008
- Description : test about C++/CLI Interface Overriding
- Release : 11/30/2008 1.0
- */
- #include "stdafx.h"
- using namespace System;
- interface class IB1
- {
- virtual void fun();
- virtual void f();
- };
- interface class IB2
- {
- void fun();
- };
- ref class D: IB1, IB2
- {
- private:
- virtual void fun1() = IB1::fun sealed//重写了B::fun
- {
- System::Console::WriteLine(L"D::fun1");
- };
- virtual void fun2() = IB2::fun sealed//重写了IB::fun
- {
- System::Console::WriteLine(L"D::fun2");
- };
- public:
- virtual void f()
- {
- System::Console::WriteLine(L"D::f");
- };
- virtual void fun() //与上面的重写无冲突
- {
- System::Console::WriteLine(L"D::fun");
- };
- };
- int main(array<System::String ^> ^args)
- {
- //String sstr;
- System::Console::WriteLine(L"********out put from an instance of D***********");
- D^ d = gcnew D;
- d->fun(); // "D::fun"
- d->f(); //"D::f"
- System::Console::WriteLine(L"********out put from an Interface IB1***********");
- IB1^ ib1 = d;
- ib1->fun(); //"D::fun1"
- ib1->f(); //"D::f"
- System::Console::WriteLine(L"********out put from an Interface IB2***********");
- IB2^ ib2 = d;
- ib2->fun(); // "D::fun2"
- String ^str = Console::ReadLine();
- return 0;
- }
从上面知道可以让接口中的函数在类的private中实现,也可以用与接口中那个函数不同的名字的函数取实现接口函数
- /*
- (C) EnzoYang 2008
- Filename : testIterface.cpp
- Compiler : Visual C++ 9.0 / Visual Studio 2008
- Description : test about C++/CLI Interface Overriding
- Release : 11/30/2008 1.0
- */
- #include "stdafx.h"
- using namespace System;
- interface class IB1
- {
- virtual void fun();
- };
- interface class IB2
- {
- void fun();
- };
- ref class D: IB1, IB2
- {
- public:
- virtual void fun() = IB1::fun
- {
- System::Console::WriteLine(L"D::fun");
- };
- };
- int main(array<System::String ^> ^args)
- {
- //String sstr;
- System::Console::WriteLine(L"********out put from an instance of D***********");
- D^ d = gcnew D;
- d->fun(); //"D::fun"
- System::Console::WriteLine(L"********out put from an Interface IB1***********");
- IB1^ ib1 = d;
- ib1->fun(); //"D::fun"
- System::Console::WriteLine(L"********out put from an Interface IB2***********");
- IB2^ ib2 = d;
- ib2->fun(); //"D::fun"
- String ^str = Console::ReadLine();
- return 0;
- }
在D中的fun式指名重写IB1接口的fun函数的情况下 , 如果IB2不能够找到其它函数指名重写它里面的fun函数时,编译器就会隐式指定D中的fun也重写IB2中的fun
- C++/CLI接口中函数重写的一些规则的例子
- C++/CLI类函数重写规则的一些例子
- C++/CLI的函数覆盖
- 学习C++/CLI的一些资源
- 学习C++/CLI的一些资源
- [C#]简单重写IComparer接口,实现自己的String.CompareTo 方法,自定义比较规则。
- Intelligencia.UrlRewriter.dll重写URL的规则例子
- C++/CLI的静态构造函数
- C语言中函数指针的例子
- 方法重写的规则
- .htaccess -------------的重写规则,
- .htaccess的重写规则
- .htaccess的重写规则
- YII的重写规则
- Java重写的规则
- 函数重载(overload)和函数重写(override)的基本规则
- java8中几个函数式接口的小例子
- java接口的一些生动的例子
- 中国市场营销资格证书
- 自制CCTV在线直播的实现
- vb 正则表达式1
- vb 正则表达式2
- 'foreground_regions' 问题
- C++/CLI接口中函数重写的一些规则的例子
- vb word插件
- 垃圾回收器 C#
- 使用MinGW编译Lua
- malloc
- 什么人适合从事软件开发工作
- C#实现附加一个数据库到SQL服务器
- 俘虏
- MacBook无损安装Leopard+XP双系统(XP三分区)