tags:

views:

119

answers:

2

I see in a class notices of a friend this:

    void show_results(Book& foreign_books) {
       int total_books

       total_books = foreign_books.getBooksNumber();
       cout << total_books << endl;
    }

this is a good class definition?

   class Book{
      public:
      Book();

      int getBooksNumber();
   };

ps: i've writing this from mobile phone, and i cannot check too much documentation(I'm newbie too). I need your confirmation. ty

+1  A: 

Except that Books and Book isn't the same (typ0)

And you have to have some data member in Books to store the number, and some way of generating it.
You probably also need some sort of factory to create a unique number for each Books()

Martin Beckett
your right, ty. solved now
dole doug
+4  A: 

It's really hard to tell what you are asking. Let me offer some criticisms, though. Maybe these will help.

The show_results method should be const-correct. That means you should pass foreign_books as a const:

const Book& foreign_books

This way, your compiler will complain if you try to modify foreign_books at all in your method.

As mgb points out, your Books class won't work because the show_results method requires a Book, not a Books. But once you fix that, you probably want to make the getBooksNumber const-correct as well:

int getBooksNumber() const;

You haven't told us what you are trying to accomplish here, so it's really hard to tell if you are close to correct in what you are doing.

Finally, you missed a semicolon in your show_results method:

void show_results(Book& foreign_books) {
   int total_books; // **here**

   total_books = foreign_books.getBooksNumber();
   cout << total_books << endl;
}
ChrisInEdmonton
dole doug
I'm not sure what you are asking. void show_results(const Book may be what you are looking for.
ChrisInEdmonton