I have to code a class template arrayPlus where objects are arrays of a type T.
The operator == must be overloaded so that two objects of the class are equal iff they are of the same type and return false otherwise.
I have overloaded it but it seems to only be defined on data of the same type. How can I define it so that it works of different data-type arrays?
Here is the code for the class template (including the operator overloading)
#include <typeinfo>
using namespace std;
template<class T> class arrayPlus {
T* type;
int nbElem;
public:
arrayPlus(int n) {
nbElem = n;
type = new T[nbElem];
};
bool operator == (arrayPlus& const obj) {
return (typeid(this->type) != typeid(obj.type));
}
};
And, in the main, this code have to compile and return false
int main(){
#include <iostream>
#include <typeinfo>
#include "arrayPlus.h"
using namespace std;
int main() {
arrayPlus<bool> arrBool(3);
arrayPlus<int> arrInt(3);
arrBool == arrInt;//<-- error
}
I get an error at the == saying
no operator "==" match these operands
operand types are: arrayPlus<bool> == arrayPlus<int>