Cercando di compilare questo semplice classe:Perché decltype non vede la dichiarazione membro?
#include <vector>
struct M
{
// interface
auto begin() -> decltype(identities.begin())
{
return identities.begin();
}
// implementation
private:
std::vector<int> identities;
};
risultati in un errore:
$ g++-510 where.cpp -std=c++11
where.cpp:57:35: error: ‘struct M’ has no member named ‘identities’
auto begin() ->decltype(this->identities.begin())
^
where.cpp:57:35: error: ‘struct M’ has no member named ‘identities’
$ clang++ where.cpp -std=c++11 -Wall -pedantic -Wextra
where.cpp:57:35: error: no member named 'identities' in 'M'
auto begin() ->decltype(this->identities.begin())
~~~~^
perché non decltype
vedere il membro della classe?
nel frattempo ho trovato una soluzione: dichiarare la variabile membro prima della uso 'decltype'. Ma qualcuno può citare lo standard che prescrive questo comportamento? O è solo più facile per gli scrittori di compilatori? – Bulletmagnet
Duplicato di http://stackoverflow.com/q/12362888/866732? – WiSaGaN
Non penso che sia un duplicato, il membro è dichiarato sopra la funzione lì. – TartanLlama