您好,我在类中使用动态数组时遇到问题。我被指示“VectorDouble 类将有一个用于双精度动态数组的私有成员变量。” 我只是为这个程序编写头文件,但我还没有完成。一旦达到容量,这个类需要能够增加一倍的大小。这是我的代码:
#include <iostream>
using namespace std;
// VectorDouble class header file
class VectorDouble
{
public:
// constructor for an empty vector of type double
VectorDouble();
// constructor that take an int argument for an integer size of and array
VectorDouble(int initial_size);
// copy constructor
VectorDouble(VectorDouble &object);
// destructor to return dynamic memory to the freestore
~VectorDouble();
// overloaded operator = for VectorDouble class
VectorDouble& operator =(const VectorDouble &source);
// overloaded operator == for VectorDouble class
friend bool& operator ==(const VectorDouble &this_vector,
VectorDouble &other_vector);
// adds a new element at the end of the array
void push_back();
// returns allocated size of VectorDouble dynamic array
int capacity();
// returns used size of the VectorDouble object
int size();
// allocates a specified block of memory for specified number of double
// type values
void reserve(int new_reserve);
// changes the size of the dynamic array
void resize(int new_size);
// returns the value at the specified index
double value_at(int index);
// changes the value at the specified index to double value d
void change_value_at(double d, int index);
private:
int count;
int max_count;
int index_pointer;
*index_pointer = new double[100];
};
我得到的错误都在这一行:*index_pointer = new double[100];
`new' 不能出现在常量表达式中
ISO C++ 禁止声明没有类型的“index_pointer”
ISO C++ 禁止初始化成员“index_pointer”
使 `index_pointer' 静态
非整数类型“int*”的静态数据成员的类内初始化无效