#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
class BookShelf
{
private:
static int MAX_BOOKS;
int count;
char* name;
class Book
{
private:
char* title;
int price;
public:
Book(char* t, int p)
{
title = new char[strlen(t) + 1];
strcpy(title, t);
price = p;
}
char* getTitle() { return title; }
int getPrice() { return price; }
};
Book* book[10];
public:
BookShelf(char* n)
{
name = new char[strlen(n) + 1];
strcpy(name, n);
count = 0;
}
void InsertBook(char* t, int p)
{
if (count==MAX_BOOKS)
{
cout << "书架已经满了\n" << endl;
}
book[count++] = new Book(t, p);
}
void ListAllBooks()
{
cout << "[" << name << "]" << endl;
for (int i = 0; i < count; i++)
{
cout << book[i]->getTitle() << book[i]->getPrice() << endl;
}
}
};
int BookShelf::MAX_BOOKS = 10;
int main()
{
BookShelf bks("salkld;sakdl;");
bks.InsertBook("book1", 23);
bks.ListAllBooks();
system("pause");
return 0;
}
这段代码也是一样的错误 |