⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e02-06.cpp

📁 游戏开发数据结构Data Structures for Game Programmers
💻 CPP
字号:
// =======================================================
//  Chapter 2, Example 6
//  Demonstrating problems with templates
//  NOTE: This example will not compile due to errors
//        deliberately introduced, to show problems.
// =======================================================
#include <iostream.h>


template<class T>
void Function( T p_item )
{
    p_item.DoSomething();
}


class ClassOne
{
public:
    void DoSomething() 
    {
        return;
    }
};


class ClassTwo
{
public:
    void DoSomethingElse() 
    {
        return;
    }
};



void main()
{
     ClassOne a;
     ClassTwo b;

     // this works fine, because ClassOne has a 'DoSomething' function.
     Function( a );

     // this causes a compiler error, because ClassTwo doesn't have
     // a 'DoSomething' function.
     // "examples\ch02\e02-06.cpp(13) : error C2039: 'DoSomething' 
     // : is not a member of 'ClassTwo'"
     Function( b );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -