problems with classes

this is my code....


#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

// Class Rectangle
class Rectangle{
public:
int x, y;

int width;
int length;

Rectangle(int x1, int y1, int w, int l)//Constructor
{
x = x1;
y = y1;

width = w;
length = l;

}

bool intersect(Rectangle r1, Rectangle r2)
{

if(r1.x+r1.length < r2.x || r2.x+r2.length < r1.x || r1.y+r1.width < r2.y || r2.y+r2.width < r1.y){
return true;
}
else {
return false;
}

}
};

int main() {


//Creating Variables & Vector
vector<int> vec;

Rectangle rec1(1,1,2,2);
Rectangle rec2(1,1,2,2);

if(intersect(rec1,rec2)){ // ERRRRRROOOOORRRR
cout << "They dont overlap" << endl;
}
else{
cout << "They do overlap" << endl;
}

//end
return 0;
}


everything works fine exept for my intersct function it tells me

"error: 'intersect' was not declared in this scope"

i have no idea what it could be... any ideas?
Last edited on
You declare intersect to be part of the rectangle class. It is not a function. It is a method of the rectangle class. You need to either call it from a rectangle, (eg if(rec1.intersect(rec1,rec2))) or declare it outside of the class, and make it a function.
Topic archived. No new replies allowed.