c++ - C++入门加Chapter14 No-type Stack
问题描述
为什么
ArrayTP<double,12> eggweights; ArrayTP<double,13> donuts;
生成两个单独的类,但Stack<int> eggs(12); Stack<int> dunkers(13)
只生成一个声明?他们不应该是两个堆栈:一个是鸡蛋堆栈,另一个是扣篮?
解决方案
嗯,这就是你的声明所说的。
ArrayTP<double,12> eggweights;
ArrayTP<double,13> donuts;
第一个变量的类型是ArrayTP<double,12>
,而第二个变量的类型是ArrayTP<double,13>
。这些是不同的。
Stack<int> eggs(12);
Stack<int> dunkers(13);
第一个变量的类型是Stack<int>
,而第二个变量的类型是Stack<int>
。这些都是一样的。
12
和13
for是它们的构造函数的eggs
参数。dunkers
期望来自不同的类型就像期望以下的不同类型:
std::string foo{"hello"};
std::string bar{"world"};