Re: const ref vs. pointer

Tech-Archive recommends: Fix windows errors by optimizing your registry



You shoul get a compiler error for the statement

Employee& GetEmployee() const;

Vladimir Grigoriev

"Luca" <nojunk@xxxxxxxxxx> wrote in message
news:eicbb9$ppv$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have 2 questions:

1. Which one is the best: Returning member variables of the class by const
ref or returning by pointer?

e.g.:

Employee* GetEmployee() const;
Employee& GetEmployee() const;

2. Which one is best: Passing a variable by const ref or by pointer?

e.g.:

void SetSalary(Employee* e);
void SetSalary(const Employee& e);

Thanks



.



Relevant Pages

  • Re: const ref vs. pointer
    ... Employee& GetEmployee() const; ... void SetSalary; ...
    (microsoft.public.vc.language)
  • const ref vs. pointer
    ... Which one is the best: Returning member variables of the class by const ... Employee* GetEmployee() const; ... Passing a variable by const ref or by pointer? ...
    (microsoft.public.vc.language)
  • Re: need infomation on const
    ... > I need clearification on using const in these following case. ... > Var y is never change in the body of function funct. ... (that is, it won't change any of it's member variables, except those ... > class CVideoObject ...
    (microsoft.public.vc.language)
  • RE: Error when returning user-defined class from "factory" class...
    ... I think you need set statements within your getemployee function since your ... Excel I've created a Factory class to instantiate objects and return them. ... Public Function getEmployee(id As Integer) As employee ... Dim emp As employee ...
    (microsoft.public.excel.programming)
  • Re: const_cast<>
    ... The compiler may insert the value ... be changed (e.g. a library that has a const missing somewhere). ... Do you mean that 'Electronics' doesn't change its own member variables, ...
    (comp.lang.cpp)