例如:
int a = 12;
cout << typeof(a) << endl;
Run Code Online (Sandbox Code Playgroud)
预期产量:
int
Run Code Online (Sandbox Code Playgroud) 我曾经使用typeid以下代码(cppreference)获取std :: vector :: size_type的类型名称和零大小的类A.
#include<iostream>
#include <vector>
#include <typeinfo>
using namespace std;
class A {};
int main()
{
vector<int> v(10);
vector<int>::size_type s = v.size();
A a;
cout << typeid(s).name() << endl;
cout << typeid(a).name() << endl;
};
Run Code Online (Sandbox Code Playgroud)
我把它作为输出:
m
1A
Run Code Online (Sandbox Code Playgroud)
我猜"A"之前的"1"是空基类优化的结果,但"m"代表什么,这是正常的吗?
我使用以下gcc版本:g ++(Ubuntu 4.4.3-4ubuntu5.1)4.4.3
我想要的方式来定义基类模板,使得它需要可变参数模板参数和定义每个参数,其中所述参数是所述参数类型的虚拟方法.
例如,Base<int, bool, string>应该给我3种虚拟方法:Foo(int),Foo(bool),和Foo(string).
我尝试了以下方法:
template <typename Param>
struct BaseSingle
{
virtual void Foo(Param) {};
};
template <typename... Params>
struct Base : public BaseSingle<Params>...
{
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,Foo变得含糊不清.我无法使用using BaseSingle<Params>::Foo...语法.有办法吗?
我知道,或者,我可以递归地从BaseSingle继承并传入剩余的参数.是否存在这方面的影响?