map*_*tts 0 c++ templates shared-ptr
我对模板的体验并不是很好,而且我在团队的代码中发现了一些令我困惑的用法.
假设我有一个基类,它有以下两个用于shared_ptr的typedef:
class Foo
{
virtual ~Foo();
virtual void bar() = 0;
};
typedef boost::shared_ptr<Foo> FooPtr1; //this is what i'm used to seeing
typedef boost::shared_ptr<class Foo> FooPtr2; //this is in our codebase
Run Code Online (Sandbox Code Playgroud)
这些typedef之间有什么区别吗?它与派生类的使用有关吗?
没有区别.
class Foo支持语法以保持一致性struct Foo,而C语言兼容性又支持该语法.在C中,a struct本身不是一个类型:与一个名为is 的结构对应的类型,通常通过a命名.在C++中,不需要,语法在很大程度上是无关紧要的.我发现为模板实例化引入"内联"标记类型很有用,例如,标记类型是不完整类型.但就是这样.Sstruct StypedeftypedefX< whatever, struct X_tag >
| 归档时间: |
|
| 查看次数: |
65 次 |
| 最近记录: |