constness dilemma

Hello forum,

I am getting a constant reference of a struct as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
struct segment
{
  std::vector<Line> lines_;
}

std::vector<Segment>  segments_;

.................
.................

const Segment &segment = segments_[segmentIndex];



But later part of the code within the function; I need to change the contents of the segment that we extracted as constant reference and I need some help to change the constness. "lines_" contents need to be changed in another function and I am sending it as follows:

1
2
3
4
5
6
7
8
9
10
11

reverseLine(const_cast<Line&>(segment.lines)); // GETTING ERROR HERE


void reverseLine(std::vector<Line> &lines)
{
   .............

   .............
}



Some hint is requested to get around this ?



Thanks
Why are you using a const-reference when you plan to modify the segment?
Topic archived. No new replies allowed.