function return value!!

I made a class called triangle for my programming hw!
In the header file that contains this class and some fuctions, there is a function called vector<triangle> findRightTriangle that gets two int as parameters! This function has to return a vector containing three int!
what i want to know is since the return value of this function is vector<triangle>, is the vector have to contain the member variables of triangle class??
Best way, post your source code as well.
We will be help you better
vector<triangle> findRightTriangles(unsigned long l, unsigned long h)
there is a function like this!!
It has to return a vector that has three integers!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class triangle {
	public:
		// member functions:
		// constructor:
		triangle(unsigned long a=3, unsigned long b=4, unsigned long c=5):
			s1(a),s2(b),s3(c) {}
		unsigned long perimeter();
		unsigned long area();
		void print();  // prints to standard output
		// member variables:
		// integers for the 3 sides:
		unsigned long s1;
		unsigned long s2;
		unsigned long s3;
};

vector<triangle> findRightTriangles(unsigned long l, unsigned long h);
bool congruent(triangle t1, triangle t2);
bool similar(triangle t1, triangle t2);


this is the class in the header file!!

so I am trying to make function in other cpp file!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vector<triangle> findRightTriangles(unsigned long l, unsigned long h) {
	triangle t1;
	t1.s1=l;
	t1.s3=h;
	t1.s2;
	for (unsigned long p = 0; p < t1.s3; p++) {
		t1.s2=p;
		if ( p >= t1.s1 && p <= t1.s3 && (((t1.s1*t1.s1)+(p*p)) == (t1.s3*t1.s3))){
			retval.push_back(t1.s1);
			retval.push_back(t1.s2);
			retval.push_back(t1.s3);
			break;
		}
	}
	
	
	return retval;
}


so in this function I made an triangle object t1.
and assign the values l and h into s1 and s3 which are the member variables in triangle class!!
In the for loop, find the appropriate value for s2 and push_back these three values and break the loop!!
and return the vector!!
there is an error!! T.,T
In function findRightTriangles

1) you dont need line #5
2) you havent declared retval
3) You need to do retval.push_back( t1 ); not
1
2
3
retval.push_back(t1.s1);
retval.push_back(t1.s2);
retval.push_back(t1.s3);
Topic archived. No new replies allowed.