![](/img/trans.png)
[英]Difference between boost::shared_ptr and std::shared_ptr from the standard <memory> file
[英]Difference between these shared_ptr instantiations?
我對模板不太熟悉,並且在團隊代碼中發現了一些用法,這讓我感到困惑。
假設我有一個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
這些typedef之間有什么區別嗎? 它與派生類的用法有關嗎?
沒有區別
支持語法class Foo
以與struct Foo
保持一致,而后者struct Foo
C兼容性而受支持。 在C中, struct
本身不是類型:與名為S
的struct S
相對應的類型是struct S
,通常通過typedef
命名。 在C ++中,不需要typedef
,並且語法基本無關。 我發現它對於為模板實例化引入“內聯”標記類型很有用,例如X< whatever, struct X_tag >
,其中標記類型是不完整的類型。 但是,僅此而已。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.