首页 > 中学考试杂题 > 题目详情
一个C++程序:向量的加 减 乘运算我编了下面的程序,模拟向量的三种运算.可是编译的时候出现错误:error C2248
题目内容:
一个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
一个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
我编了下面的程序,模拟向量的三种运算.
可是编译的时候出现错误: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
本题链接: