【发布时间】:2014-04-20 06:18:59
【问题描述】:
我正在尝试将一个节点分配给一个指针数组中的指针,但它一直告诉我我的数组未在范围内声明。我完全不知道如何或为什么任何帮助都会大有裨益!感谢您抽出宝贵时间回复!
#include <iostream>
#include "book.h"
using namespace std;
class bookstore
{
private:
int amount = 5;
int counting = 0;
public:
bookstore()
{
bookstore *store;
store = new book*[amount];
for(int i = 0; i < amount; i++)
{
store[i] = NULL;
}
}
~bookstore(){ delete[] store; }
void addbook(string a,string b, string c, string d, string e)
{
if (counting == amount)
{
cout<<"Full House!"<<endl;
return;
}
store[counting] = new book(a,b,c,d,e);
counting++;
}
void print()
{
for(int i = 0; i < amount; i++)
{
cout<<store[i]->name<<" "<<store[i]->publisher<<" "<<store[i]->year<<" "<<store[i]->price<<" "<<store[i]->category<<endl;
}
}
};
【问题讨论】:
-
在 C++ 中,如果您在大括号
{ ..... }内的函数中声明变量,则在}之后将不再存在。