fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. namespace mynamespace
  4. {
  5. struct Book
  6. {
  7. private:
  8. std::string bookname;
  9. std::string author;
  10. int pages;
  11. public:
  12. Book() : bookname(),author(),pages()
  13. { }
  14. Book(const std::string& name,const std::string& aut,int p) : bookname(name),author(aut),pages(p)
  15. { }
  16. void print() const;
  17. };
  18. void Book::print() const
  19. {
  20. std::cout<<"Book name is "<<bookname<<'\n';
  21. std::cout<<"Book author is "<<author<<'\n';
  22. std::cout<<"Total book pages "<<pages<<'\n';
  23. }
  24. void foo(const Book& b)
  25. {
  26. b.print();
  27. }
  28. }
  29. int main()
  30. {
  31. mynamespace::Book b("Andrei Alexzandrescu","Modern C++ Design",333);
  32. foo(b);
  33. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Book name is Andrei Alexzandrescu
Book author is Modern C++ Design
Total book pages 333