首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模板

2012-03-09 
模板高手请进!#include iostream#include vectorusingnamespacestdstructA{voidf(){cout usingA

模板高手请进!
#include <iostream>
#include <vector>
using   namespace   std;


struct   A   {void   f(){cout < < "using   A " < <endl;}};
struct   B   {void   f(){cout < < "using   B " < <endl;}};
struct   C   {void   f(){cout < < "using   C " < <endl;}};

template <int>
struct   ResultType;
template <>   struct   ResultType <1>
                    {typedef   A   type;};
template <>   struct   ResultType <2>
                    {typedef   B   type;};
template <>   struct   ResultType <3>
                    {typedef   C   type;};

template <int   useTypeFlags>
class   actualClass{
public:
typedef   typename   ResultType <useTypeFlags> ::type   MyType;
public:
    vector <MyType>     myVec;
};

actacualClass   <   3   >       X3;注释掉是正确的,去掉注释是错误的!

int   main()
{
       
}
f:\beifen\腐蚀\腐蚀\aaa.cpp(27)   :   error   C2143:   syntax   error   :   missing   '; '   before   ' < '
f:\beifen\腐蚀\腐蚀\aaa.cpp(27)   :   error   C4430:   missing   type   specifier   -   int   assumed.   Note:   C++   does   not   support   default-int

问题1:下面这一句是什么意思呢?
error   C4430:   missing   type   specifier   -   int   assumed.   Note:   C++   does   not   support   default-int

问题2:
如何更正错误呢?

[解决办法]
actacualClass <3> X3;
改成
actualClass <3> X3;

热点排行