Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 11, 2015 06:34
Show Gist options
  • Save krysseltillada/4b9d2fc59ee16f84ecf7 to your computer and use it in GitHub Desktop.
Save krysseltillada/4b9d2fc59ee16f84ecf7 to your computer and use it in GitHub Desktop.
function member as friend
#include <iostream>
class Person;
class option
{
public:
typedef int number;
option () = default;
option (std::string &, std::string &, number &, number &);
void modify (const std::string &,const std::string &, Person &);
void modify (std::string &, std::string &, number &, number&, Person &);
};
class Person
{
public:
friend void display (Person &, std::ostream &);
typedef int number;
Person () = default;
Person (const std::string &n, const std::string &a, const number &ag, const number &id) :
name (n), address (a), age (ag), idno (id) { }
Person (const std::string &n, const std::string &a) :
name (n), address (a) { }
friend void option::modify (const std::string &,const std::string &, Person &);
friend void option::modify (std::string &, std::string &, number &, number &, Person &);
private:
std::string name, address;
number age = 0, idno = 0;
};
void option::modify (const std::string &n,const std::string &a, Person &p1)
{
p1.name = n;
p1.address = a;
}
void option::modify (std::string &n, std::string &a, number &ag, number &id, Person &p1)
{
p1.name = n;
p1.address = a;
p1.age = ag;
p1.idno = id;
}
void display (Person &p1, std::ostream & os)
{
os << std::endl
<< p1.name << std::endl
<< p1.address << std::endl
<< p1.age << std::endl
<< p1.idno << std::endl;
}
int main ()
{
Person p1("kryssel", "las pinas city", 22, 23);
display (p1, std::cout);
option op1;
op1.modify ("kryssel tillada", "las pinas city", p1);
display (p1, std::cout);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment