我有两个类:复合类和类矩阵。C++类构造函数()
不是我的构造函数应该替代void参数构造函数吗?它会抛出一个错误util我也声明Complex()构造函数。克++ -std = C++ 14
Complex.h
class Complex {
private:
int m_real, m_imaginary;
public:
Complex(const int, const int);
}
complex.cpp
#include "Complex.h"
// Constructor
Complex::Complex(const int real = 0, const int img = 0) : m_real(real), m_imaginary(img) { }
Matrix.h
class Complex;
class Matrix {
private:
int m_lines, m_columns;
Complex *m_matrix;
public:
Matrix(const int, const int, const Complex &);
}
matrix.cpp
#include "Matrix.h"
#include "Complex.h"
Matrix::Matrix(const int nr_lines, const int nr_columns, const Complex &comp) : m_lines(nr_lines), m_columns(nr_columns) {
m_matrix = new Complex[nr_lines * nr_columns];
some other code goes here...
| 7 |错误:没有用于调用'Complex :: Complex()'的匹配函数|
您可以尝试创建一个[最小化,完整和可验证示例](http://stackoverflow.com/help/mcve)并向我们展示?加上你得到的实际错误(完整,完整和未经编辑)? –
而不是原始数组,为什么不使用'std :: vector'? – crashmstr
请提供更多的上下文。如果有错误,则将错误消息的文本复制到您的问题。如果这是Visual Studio,则“输出”选项卡将出现可作为文本复制的窗体中的错误。 – drescherjm