Cannot bind CType*& reference to temporary CType* in C++

  • Context: C/C++ 
  • Thread starter Thread starter neurocomp2003
  • Start date Start date
  • Tags Tags
    Local Reference
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 4K views
neurocomp2003
Messages
1,359
Reaction score
4
i have this following code with local var as a "ref. to ptr"

class node {
CType* data;
CTYpe* operator*() { return data; }
}
void F(node *a, node *b)
{
CType*& tp; tp=**a;
}

I get the error "Cannot convert CType* to CType*&
which i sort of understnad but i do not know how to resolve this.
The reason I'm looking to do this is so that i don't have (**a).Data() throughout my code but rather tp.Data(); and i need it to be a reference otherwise it would not change the variable outside of hte Fx.

I guess i can use a ptr to ptr(CType**) but i'd much rather just use a C++ reference. and if i do tp=***a i still get a error.

thanks in advance
 
Physics news on Phys.org
The example is kind of hard to follow, what is it youre trying to do? could you spell out the goal of the coding?

Using the Address of operator, is that for a function call? Do you want to manipulate objects with a pass by reference? It looks like a 3D array in there?
 
Brad, he is overloading the unary operator *. The purpose of this is so when he asks for the pointer of a node object, he gets the pointer of data instead.neurocomp2003, If you do this:

Ctype* tp; tp=**a;

then you would do this:

(*tp).data()

The other option is to do something like this:

CType*tp; tp=a->data;

Then you would do this:

tp->data();

This is of course assuming you make data public. Either that, or you make the function F a friend of node.
 
Last edited: