call by value
call by reference
class Dog{
public :
Dog(std::string name): _name(name){};
Dog(Dog &obj){
std::cout << "*copy constructor*" << std::endl;
_name = obj._name;
} // copy constuctor
std::string getName(){ return (_name); }
private :
std::string _name;
};
void passingWithReference(Dog &dog){
std::cout << dog.getName() << std::endl;
}
void passingWithValue(Dog dog){
std::cout << dog.getName() << std::endl;
}
int main(){
Dog dog("ddung");
std::cout << "call by value" << std::endl;
passingWithValue(dog);
std::cout << "call by reference" << std::endl;
passingWithReference(dog);
return (0);
}
output >
call by value
*copy constructor*
ddung
call by reference
ddung