I have the following problem:
//A.h
class A
{
//...
// this is the important part, i have to call this in the proper way
// in A::SetNewValue(), but i don't know how to do that
protected:
void SetValue(const int* i);
//...
public:
// ??
void SetNewValue(const int* p);
}
the cpp:
//A.cpp
//??
A::SetNewValue(const int* p)
{
// ??
this->SetValue(&p);
}
and…
//...
// and later in another file...
//...
A a = new A();
int a_value = 4;
int* p;
p=&value;
// ??
a->SetNewValue(p);
The problem explained: class A is a built-in class in a framework. I have no way to modify protected A::SetValue() to public, and I can’t reach it from ‘outside’. So i’ve decided to write another function A::SetNewValue() to call A::SetValue, but I don’t know how to pass pointers and references in function parameters. I’ve always got erros like: can’t convert from * to &, const * to *, and so on…
How can i do this in a proper way? Is this even possible?
Thank you very much for your effort, and for your help.
Edit: Code above is a sample.. I’ve tried passing parameters in several ways
SetValuetakes a pointer just likeSetNewValueso you can pass the pointer value straight through:I also fixed the missing
voidreturn type in your function definition.You should be able to call it with a pointer to
intorconst intbecause you can always add aconstat the top level when passing pointer.:I fixed your
avariable to be just default constructed; I think that trying initialize a non-pointerawith a pointer toA(fromnew A) was probably a mistake.I changed
->to.asais not a pointer.