I want my function to return an array of objects. But i want some restriction on returned reference so that returned value/reference is not modified by caller.
Eg
class A
{
B **arrB;
public :
A()
{
initialize arrB
}
B** getB()
{
return arrB;
}
}
In above code, array returned by getB() function, should not be modified.
Can someone suggest best way to do this ?
Can "const" help?
Yes it will help. But then you will get an error about illegal conversion from
B **toconst B **, but that is the reason forconst_cast:Note that I added an extra
constqualifier after the function declaration. This tells the compiler that the function does not modify anything in the class.