This function should be declared as const (because it returns data and doesn't modify it), otherwise you can't call it on constant instances. E.g:
Code:
void foo(const Var& v)
{
v.toString(); //discards qualifiers error, unless toString is a const method
}
As to casts:
if you want to return a reference, you don't need a cast. This is how you normally make a reference to something (i doesn't have to be a reference for a reference to refer to it):
Code:
int i = 42;
int& ref = i; //note: no cast!
If __data is a std::string then casting it to std::string is meaningless.
I seem to remember that you had other rather meaningless casts in your code, such as:
If it didn't already work without that cast (because Var has a non-explicit constructor that takes an integer argument), then the cast wouldn't do the right thing either. Normal ways to declare and initialize an instance:
Code:
Var x(42);
Var x = 42; //if the constructor is not explicit
Var x = Var(42); //copy from a temporary