Re: Equates or Synonyms?
Mike Copeland wrote:
capability to "equate" or use a synonym for
an identifier?
Alf P. Steinbach wrote:
Yes, but it depends on the kind of identifier.
References work for v
On 28 Nov., Mike Copeland wrote:
^^^^^^^^^^^^^^^^^^^^^
I don't understand what you mean here.
He means something like this:
struct DEF_STRUCT
{
int EPace;
int& ABetterNameForEPace;
/* snip */
// This constructor for DEF_STRUCT binds
// ABetterNameForEPace to EPace.
DEF_STRUCT ()
: ABetterNameForEPace (EPace)
{}
};
Then you can do:
DEF_STRUCT s;
s.EPace = 5;
std::cout << s.ABetterNameForEPace << std::endl;
s.EPace = 7;
std::cout << s.ABetterNameForEPace << std::endl;
and you'll get the output
5
7
Note that introducing references may alter the binary layout of your
struct. Most probably the reference will be implemented through an
additional pointer.
There is a non-portable compiler extension for Microsoft Visual C++
which lets you achieve the same thing but without any changes to the
binary layout. Google for __declspec property.
However, the simplest would be to just add a setter and getter method
to the struct:
struct DEF_STRUCT
{
int EPace;
int getABetterNameForEPace ()
{
return EPace;
}
void setABetterNameForEPace (int NewValue)
{
EPace = NewValue;
}
/* snip */
};
Regards,
Stuart
PS: Please keep the names of the people you are quoting from. Better
yet, keep a complete history of the talk (at least the part that you
are refering to). Not everybody has access to all postings of this
group.