boolean and return

1
2
3
4
5
6
7
8
9
class Triangle 
{
public:
    bool Set(double aa, double bb , double cc ); 
private:
	 double a;
	 double b;
	 double c;
};


1
2
3
4
5
6
7
8
9
10
11
bool Triangle::Set( double aa, double bb , double cc )
	{	    a=aa;
		    b=bb;
		    c=cc;
		    if (aa + bb <= cc || aa + cc <= bb || bb + cc <= aa)
		 return 1 ;
		 	
    	else	   
        	 return 0 ; 
	}


1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
 int d;
  Triangle r;
 
   r.Set()=d;
  If (d==1);
 	 {
          ....
	  }

   return 0;


Hi . This a just a part of my project i`m working on. and i have question. how can i return 1 or 0 from bool Triangle::Set() function example? every time i`m trying to execute this it show me an error "[Error] no matching function for call to 'Triangle::Set()'"
and "[Note] candidate expects 3 arguments, 0 provided"
thanks in advance
Last edited on
Maybe pass parameters to the line 6 of the main.

The error message is saying it.

Btw Set return a r-value here, so you want write "r.set([your args]) = [something]".
You have to do "[something] = r.set([your args])".

By the way, please use true and false macro instead of 1 and 0 for booleans.
Last edited on
Hello defs,

There is more than one problem here.

When you use "=" to assign it makes a difference in the order. In this case it works right to left.

To start with what you want is d = r.set(...);. next the "set" function takes three variables and you are sending nothing.

Since your are returning a "bool" from the function "d" should be defined as a "bool" not an "int" although it will work.

The if statement could be simply written as if (d) and it will work the same as what you have. Try to take advantage of what you have to work with.

Come up with better names for your variables. This is more for your benefit. Single letters and even your double single letters can be hard to follow in a larger program. Try to use a noun or sometimes a verb that describes what the variable is for or does.

Andy
Thank you Andy and Zaap.
I did edited code and i did understand that i had a bigger issue in code , fixed it. Thank you again ;)
Topic archived. No new replies allowed.