【发布时间】:2021-12-23 23:32:39
【问题描述】:
我在看下面video
这里提到g++会报错如下代码:
#include<vector>
#include<typeinfo>
#include<iostream>
struct S
{
std::vector<std::string> b ;
};
int main()
{
S s;
std::cout << typeid(S::b).name();
}
error: invalid use of non-static data member ‘S::b’
但是我在msvc和clang下没有遇到这种错误。谁是对的,为什么? 还有为什么改成
typeid(&S::b).name();
之后的结果正确吗?
【问题讨论】:
标签: c++ visual-c++ g++ clang++ typeid