以下の内容はhttp://blog.livedoor.jp/cppcli/archives/414477.htmlより取得しました。


2010年07月28日

クラス

C++にはインターフェースクラスがありません。
インターフェースクラスを表現したいときは抽象クラスを使います。
C++には多重継承がありますが、CLIには多重継承がありません。
複数のインターフェースを実装することはできます。
 C++CLI
インターフェース
interface

-

複数インターフェースの実装
interfaces

-

抽象クラス
abstract

 ○

継承
base

多重継承
bases

 ○

-



インターフェース

[CLI]
interface class Interface1 {
    void Method1();
};
interface class Interface2 {
    void Method2();
};
ref class Implement : Interface1, Interface2 {
public:
    virtual void Method1() {}
    virtual void Method2() {}
};

void func1(Interface1^ server)
{
    server->Method1();
}
void func2(Interface2^ server)
{
    server->Method2();
}

int main()
{
    Implement^ implement = gcnew Implement();
    func1(implement);
    func2(implement);
    return 0;
}

抽象クラス

[C++]
class Abstract {
public:
    virtual void Method1() = 0;
    void Method2() {}
};
class Concrete : public Abstract {
public:
    virtual void Method1() {}
};

void func(Abstract* obj)
{
    obj->Method1();
    obj->Method2();
}

int main()
{
    func(new Concrete());
    return 0;
}
[CLI]
ref class Abstract abstract {
public:
    virtual void Method1() abstract;
    void Method2() {}
};

ref class Concrete : Abstract {
public:
    virtual void Method1() override {}
};

void func(Abstract^ obj)
{
    obj->Method1();
    obj->Method2();
}

int main()
{
    func(gcnew Concrete());
    return 0;
}

継承

[C++]
class Base1 {
public:
    void Method1() {}
};
class Base2 {
public:
    void Method2() {}
};
class Derived : public Base1, public Base2 {
public:
    void Method3() {}
};

int main()
{
    Derived* derived = new Derived();
    derived->Method1();
    derived->Method2();
    derived->Method3();
    return 0;
}
[CLI]
ref class Base {
public:
    void Method1() {}
};

ref class Derived : Base {
public:
    void Method2() {}
};

int main()
{
    Derived^ derived = gcnew Derived();
    derived->Method1();
    derived->Method2();
    return 0;
}





以上の内容はhttp://blog.livedoor.jp/cppcli/archives/414477.htmlより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14