Category : operator-overloading

Issue I want to overload the operator += in the class of Complex, but I get this error when I compile this project by g++ main.cpp complex.cpp -I complex.hpp -o out: Undefined symbols for architecture x86_64: "Complex::operator+=(Complex const&)", referenced from: _main in main-bee8d4.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed ..

Read more

I wrote a struct to maintain a state of tic-tac-toe game. struct Board{ std::vector<std::vector<int>> board; Board() { board = std::vector<std::vector<int>> (3, std::vector<int> (3)); } std::vector<int> & operator[](int id) { return board[id]; } int & operator[](std::pair<int, int> pos) { return board[pos.first][pos.second]; } }; It works fine, and I can access the values within the struct in ..

Read more

Hello I’m always getting an error when i do overloading can someone please explain my error here. Main file: #include <iostream> #include <string> #include "couche.hpp" using namespace std; int main(){ Couche C(5.2,6.3); cout<< C.get_lambda(); std::cout<< C; } .hpp file: #include <string> using namespace std; class Couche{ private: double epaisseur; double lambda; public: // constructeur: Couche(double ..

Read more

I am writing an abstract CRTP-based abstract base class for static/dynamic arrays. I intend to put as many methods as possible in the base class so that there is no code duplication in the derived classes. I have got the indexing operator working but I’m struggling with the assignment (=) operator. /** Array base class. ..

Read more

I am implementing this class from https://isocpp.org/wiki/faq/operator-overloading class Matrix { public: Matrix(unsigned rows, unsigned cols); double& operator() (unsigned row, unsigned col); // Subscript operators often come in pairs double operator() (unsigned row, unsigned col) const; // Subscript operators often come in pairs // … ~Matrix(); // Destructor Matrix(const Matrix& m); // Copy constructor Matrix& operator= ..

Read more

I’m currently doing practicing on the ->* operator with the intent to write a smart pointer. I’ve done the basics on how it works. For this example I want to use templates when using operator->*(), so I can use member functions for a variety of return and paramater types. Below is a simple example of ..

Read more