一个C++程序:向量的加 减 乘运算我编了下面的程序,模拟向量的三种运算.可是编译的时候出现错误:error C2248:'len' :cannot access private member declared in class 'vector'see declaration of 'len'把v和len改为工友成员后编译成功,可是程序运行到一半时就会弹出错误为什么呢请大虾们指点一下啊`````#include#includeclass vector{public:vector(int =1);vector(int *,int );vector(vector&);vector();friend vector operator+(vector&,vector&);friend vector operator-(vector&,vector&);friend int operator*(vector&,vector&);vector & operator=(vector&);friend ostrea

问题描述:

一个C++程序:向量的加 减 乘运算
我编了下面的程序,模拟向量的三种运算.
可是编译的时候出现错误:error C2248:'len' :cannot access private member declared in class 'vector'
see declaration of 'len'
把v和len改为工友成员后编译成功,可是程序运行到一半时就会弹出错误
为什么呢
请大虾们指点一下啊`````
#include
#include
class vector
{public:
vector(int =1);
vector(int *,int );
vector(vector&);
vector();
friend vector operator+(vector&,vector&);
friend vector operator-(vector&,vector&);
friend int operator*(vector&,vector&);
vector & operator=(vector&);
friend ostream&operator(ostream &output,vector &);
private:
int *v;int len;
};
vector::vector(int size)
{if(size100){cout

将vector::vector(int *B,int size)中的代码
B=new int[size];
修改为
v=new int[size];