G
Greg Shaw
All,
This is driving me up the wall! I have a class member which is a
short, and I want to write an accessor method which will return a
short* pointing to the address of that data member. It should be so
simple, but my compiler is having none of it...
I've tried decaring the method inline like so:
class theClass
{
public:
//.... constructors, destructor, other accessors here, then -
short* GetMemberAddr() const
{ return &theMember;}
private:
short theMember;
//....
};
This way, the compiler complains that the return type does not match
what is being returned. I don't get it - the address of a short must
be a short* .
So I thought I'd try defining the accessor outside the class
declaration like so -
class theClass
{
public:
//.... constructors, destructor, other accessors here, then -
short* GetMemberAddr() const;
private:
short theMember;
//....
};
short* theClass::GetMemberAddr()
{
return &theMember;
}
This way, the compiler complains that the definition "short*
theClass::GetMemberAddr()" does not match the declaration "short
theClass::*GetMemberAddr() " .
I've tried sticking parentheses around the function name in both
places so as to make it clear that I want it to be dealt with first
before it's assigned to return a short* , but it doesn't work.
Any suggestions? I think I'm going mad. And no, it isn't homework,
it's a self-imposed learning task which I've been slogging away at for
hours now.
This is driving me up the wall! I have a class member which is a
short, and I want to write an accessor method which will return a
short* pointing to the address of that data member. It should be so
simple, but my compiler is having none of it...
I've tried decaring the method inline like so:
class theClass
{
public:
//.... constructors, destructor, other accessors here, then -
short* GetMemberAddr() const
{ return &theMember;}
private:
short theMember;
//....
};
This way, the compiler complains that the return type does not match
what is being returned. I don't get it - the address of a short must
be a short* .
So I thought I'd try defining the accessor outside the class
declaration like so -
class theClass
{
public:
//.... constructors, destructor, other accessors here, then -
short* GetMemberAddr() const;
private:
short theMember;
//....
};
short* theClass::GetMemberAddr()
{
return &theMember;
}
This way, the compiler complains that the definition "short*
theClass::GetMemberAddr()" does not match the declaration "short
theClass::*GetMemberAddr() " .
I've tried sticking parentheses around the function name in both
places so as to make it clear that I want it to be dealt with first
before it's assigned to return a short* , but it doesn't work.
Any suggestions? I think I'm going mad. And no, it isn't homework,
it's a self-imposed learning task which I've been slogging away at for
hours now.