I have a class that represents a special number.
class SecretInteger
{
private:
unsigned int *data;
size_t length;
public:
SecretInteger operator+(const SecretInteger other) const;
}
I can't allow any other part of my code have access to the data
variable. However, my operator+
function MUST be able to see it. Usually in this case I know that using the friend
keyword is the only way to do it. However when I write:
friend SecretInteger operator+(const SecretInteger other);
It claims that the operator+
cannot be declared as friend, even though I've previously wrote friend std::ostream& operator<<(std::ostream& stream, const SecretInteger val);
and it works fine.
What options do I have available to me? If I have a public method like
const *unsigned int getData() const;
I think even then it doesn't actually make the variable returned const
right? I'd really prefer not to have a getData()
method and instead just declare the functions that have access as friend
.