我可以在向量的实例上使用value_type,而不是在其类型上

NoS*_*tAl 5 c++ sizeof

在玩和尝试计算向量的总大小时,我尝试了类似的东西

vector<double> vd;
auto area = vd.size()* sizeof (vd::value_type); 
//Ive seen Stepanov use area as name for this kind of size, idk if he adds the sizeof vd also to area :)
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用......我需要使用,vector<double>::value_type但这会使代码的可读性降低.可以使它工作吗?我不喜欢sizeof vd.front()因为它写起来看起来很难看front().
编辑:decltype变体也适合我称之为丑陋的类别...

hmj*_*mjd 7

认为 decltype可以使用:

auto area = vd.size() * sizeof(decltype(vd)::value_type);
Run Code Online (Sandbox Code Playgroud)

当你使用auto我假设C++ 11是允许的.

用g ++ v4.7.2和clang v3.3确认.