Heya!
I've coded my own reference pointer template class but I'm having one problem with it that I don't really know how to solve. I'll try to explain with two examples.
This works fine:
1 2 3 4 5 6
|
{
typedef ReferencePointer<Foo> FooRef;
FooRef FooObject = new Foo; //FooObject saves the address of Foo and .addref's it
FooObject->DoWhatEver(); // Does what ever
} //FooObject dies, decrefs the foo it's pointing too which also gets destroyed
// since its refcount is 0
|
Now i have a function that will just read from my FooObject so i want to send it in as const
1 2 3 4 5 6
|
{
typedef ReferencePointer<Foo> FooRef;
const FooRef FooObject = new Foo; //FooObject saves the address of Foo and .addref's it
FooObject->DoWhatEver(); // compiler error(see below)
} //FooObject dies, decrefs the foo it's pointing too which also gets destroyed
// since its refcount is 0
|
the compiler error i get:
error C2678: binary '->' : no operator found which takes a left-hand operand of type 'const CMeshStructureRef' (or there is no acceptable conversion)
I have tried doing the following to my reference pointer template:
const T* operator-> ()
{
return m_pObject;
}
This didn't work since it's the same parameterlist(empty) as for T* operator-> ()
const T* GetConst()
{
return m_pObject;
}
but when i do FooObject.GetConst() i get:
cannot convert 'this' pointer from 'const CMeshStructureRef' to 'ReferencePointer<T> &'
I'm a bit over my head here, a solution to solve this would be great but also, why didn't my GetConst() work? I can't really interpret the error message in a sensible way:P