c++ - Operator Overloading (int as bool) -
i'm trying write code returns 1s , 0s instead of true or false. doesn't seem right.
int short_vector::operator==(const short_vector& obj){ if(a == obj.a && b == obj.b && c == obj.c && d == obj.d){ return 1; }else{ return 0; } }
so should return value each variable.
i tried this:
int short_vector::operator==(const short_vector& obj){ int a_tf, b_tf, c_tf, d_tf; if(a == obj.a){ a_tf = 1; }else{ a_tf = 0; } if(b == obj.b){ b_tf = 1; }else{ b_tf = 0; } if(c == obj.c){ c_tf = 1; }else{ c_tf = 0; } if(d == obj.d){ d_tf = 1; }else{ d_tf = 0; } return(a_tf, b_tf, c_tf, d_tf) }
but got error commas being operator.
edit
getting error: error: conversion 'int' non-scalar type 'short_vector.
i'm trying represent vector looks [9,1,5,5].
then i'll
`short_vector a(2, 6, 9, 4); short_vector b(3, 8, 7, 6); short_vector c = == b; cout<<c;`
output then: [0,0,0,0]
if want have result short_vector
, try this:
short_vector short_vector::operator==(const short_vector& obj) { return short_vector( == obj.a, b == obj.b, c == obj.c, d == obj.d ); }
Comments
Post a Comment