c++ - 在另一个构造函数中调用构造函数(没有要调用的匹配函数......)c++

标签 c++ arrays constructor

我已经编写了一个 Array 类来创建 1d、2d 和 3d 数组,它在每个测试中都能正常工作:2d 情况下数组类的构造函数示例:

Array::Array( int xSize, int ySize )
{ 
xSize_ = xSize;
ySize_ = ySize;
zSize_ = 1;
vec.resize(xSize*ySize);
}

它工作正常,但是当我需要在其他构造函数中使用这个构造函数时,我得到“无匹配函数错误”, 我的部分代码:

class StaggeredGrid
{
public:
StaggeredGrid ( int xSize1, int ySize1, real dx, real dy ) : p_ (2,2) {}
protected:
Array p_;

完整错误:

No matching function for call to Array::Array() 
Candidates are : Array::Array(int)
Array::Array(int, int)
Array::Array(int, int, int)

如果有人知道这个问题,我将不胜感激

最佳答案

您的 Array 类具有三个构造函数,分别采用一个、两个和三个整数。如果 StaggeringGrid 有一个默认的构造函数,它将根据您所说的调用 Array::Array(),它不存在。

关于c++ - 在另一个构造函数中调用构造函数(没有要调用的匹配函数......)c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19846126/

相关文章:

c# - 从 Constructor 调用一个工厂得到新版本的 "this"

c++ - C++ 中类静态变量的生命周期是多少?

java - SWIG 生成的代码不处理或抛出异常

c++ - 自动生成成员函数的 const 重载

c++ - TLS 握手消息解析

java - Java 中的 Euler Challenge 1 - 我做错了什么?

c++ - 打乱矩阵

javascript - 求和对的唯一排列 : Javascript Algorithm

java在第二类中找不到构造函数

c++ - move 构造函数和右值引用