小编Ken*_*han的帖子

使用CRTP和typedef的"继承"类型

以下代码无法编译.我收到一条错误消息:错误C2039:'Asub':不是'C'的成员

有人能帮助我理解这个吗?

试过VS2008和2010编译器.

template <class T>
class B
{
    typedef int Asub;

public:
 void DoSomething(typename T::Asub it)
 {

 }
};

class C : public B<C>
{
public:
 typedef int Asub;

};

class A
{
public:
 typedef int Asub;

};


int _tmain(int argc, _TCHAR* argv[])
{
 C theThing;
 theThing.DoSomething(C::Asub());

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ templates

5
推荐指数
1
解决办法
945
查看次数

模板类型的 C++ 模板特化

我希望通过使用 BOOST_STATIC_ASSERT 来帮助我的一些模板代码的用户,让他们知道他们使用了不兼容的类型,其编译错误消息比当前使用不兼容类型生成的怪物更简单。

这个例子有点太复杂了,无法在这里重现,但希望这能抓住我想要的本质:

我的问题是如何格式化最后一行“模板模板”?

template <typename P1, int P2, typename P3> 
class InterestingType

{
}

template<typename T>
struct is_interesting_type{
 static const bool value = false;
};

template<template<typename,int,typename> typename InterestingType> //No idea how to format this..
struct is_interesting_type{
 static const bool value = true;
};
Run Code Online (Sandbox Code Playgroud)

c++ templates traits

5
推荐指数
1
解决办法
120
查看次数

标签 统计

c++ ×2

templates ×2

traits ×1