I have two classes: a class Complex and a class Matrix.
Isn't my constructor supposed to substitute the void arguments constructor as well? It throws an error util I declare Complex() constructor as well. g++ -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|error: no matching function for call to 'Complex::Complex()'|
std::vector<std::vector<std::complex<int>>>should suffice.realandimgin your code? If there wasn't any default values thennew Complex[n]would have thrown error withoutComplex().