簡體   English   中英

C2228使用decltype時出錯

[英]C2228 Error when using decltype

早上。 我目前正在嘗試使用C ++創建Graph類(Visual Studio 2013年11月CTP)。 我正在制作一個Incidence類來存儲邊。 我想將Incidence類的內部Container存儲在typedef中,而不是在模板定義中添加另一個typename,以便使類定義更通用,但是使用'using x = decltype(y)'會導致錯誤C2228'在必須具有class / struct / union'。 我已經嘗試過Google,但沒有找到解決方案。

碼:

#include<list>
#include<vector>

template<typename Container = std::list<std::vector<bool>>>
class Incidence
{
private:
Container   Connections;
using Contained = decltype(Connections.at());
using Connections_Size_T = decltype(Connections.size());

public:

template<typename Index>
inline Contained operator[](Index Input_Index)
{return Connections[Input_Index];}

inline Connections_Size_T size()
{return Connections.size();}
};

回答自己的問題:不像我希望的那樣整潔,但至少直接使用decltype()-函數進行編譯和運行:

template<typename Container = std::list<std::vector<bool>>>
class Incidence
{
private:
Container   Connections;
public: 
template<typename Index>
inline auto operator[](Index Input_Index) -> decltype(Connections[])
{return Connections[Input_Index];}

inline auto size() -> decltype(Connections.size())
{return Connections.size();}
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM