Consider the following class member:
std::vector<sim_mob::Lane *> IncomingLanes_;
the above container should store a pointer to some if my objects are lane. I do not want routines to use this variable as an argument to be able to modify Lane objects. At the same time, I do not know where to put the keyword 'const', which does not prevent me from filling the container.
Could you help me with this?
Thank you and respect vahid
Edit:
Based on the answers I have received so far (many thanks to all of them), suppose this sample:
#include <vector>
#include<iostream>
using namespace std;
class Lane
{
private:
int a;
public:
Lane(int h):a(h){}
void setA(int a_)
{
a=a_;
}
void printLane()
{
std::cout << a << std::endl;
}
};
class B
{
public:
vector< Lane const *> IncomingLanes;
void addLane(Lane *l)
{
IncomingLanes.push_back(l);
}
};
int main()
{
Lane l1(1);
Lane l2(2);
B b;
b.addLane(&l1);
b.addLane(&l2);
b.IncomingLanes.at(1)->printLane();
b.IncomingLanes.at(1)->setA(12);
return 1;
}
I mean:
b.IncomingLanes.at (1) → printLane ()
should work on IncomingLanes no problem AND
b.IncomingLanes.at (1) → set A (12)
. ( !)
, . , , , , .
Thaks agian