Copying one struct to another

I have a class in which one of it's member variable is a struct.
The constructor of the class get the struct as parameter, such the member variable are able to take the values from the struct and save it into the object. but when i am trying to do so, get an error saying reference to non-static member function must be called
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

class jail{
public:
    jail(polygon figure){
    corners  = figure // here is where the error appear..
     

};

    polygon corners();

};

struct polygon{
    int x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;
polygon(int x_1, int y_1, int x_2, int y_2, int x_3, int y_3, int x_4, int y_4)
    :x_1(x_1),y_1(y_1),x_2(x_2),y_2(y_2),x_3(x_3),y_3(y_3),x_4(x_4),y_4(y_4){}
};


what is the problems?
corners is a function which takes no arguments and returns polygon. You cannot assign anything to it.
closed account (SECMoG1T)
Line 4, 10
jail(polygon figure)//// polygon is not yet in scope ... not very sure though...

Line 16 similar parameter and member variable names in same scope not a good idea
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
using namespace std;
struct polygon{
    int x, y;
polygon(int x1, int y1) : x(x1), y(y1) {}
};


class jail{
	polygon corners;
public:
    jail(polygon p1) : corners(p1)  {  //////
    // here is where the error appear..  

	}
    //polygon corners();

};



int main()
{
	polygon p1(1,2);
	
	jail j1(p1);	
	
	return 0;
}
So.. how can i resolve it?..
I don't see why the problem appear at all..
i've added a normal constructor, and now i get a linker fail..
my example worked fine. use member initializer list in constructors instead of in braces {...}
Topic archived. No new replies allowed.