期待高人解决一个问题!!!!(c++)

来源:百度知道 编辑:UC知道 时间:2024/06/03 20:43:42
我想知道下面这个程序为啥错了,怎样修改!!!

#include <iostream>
using namespace std;
class MyTest
{
public:
int *number;
int count;

MyTest()
{
number=new int[20];
count=0;
}
void AddTail(int num)
{
number[count]=num;
count++;
}
friend ostream & operator << (ostream &os, const MyTest &my);

};

ostream & operator << (ostream &os, const MyTest &my)
{
for (int i=0;i<20;i++)
{
os<<my.number[i]<<" "<<endl;
}
return os;
}

class Second
{

public:
static MyTest test;
Second()
{

}
void OP()
{
for (int i=0;i<20;i++)
{
test.AddTail(i);
}
cout<<test;
}
};
void main()
{
Second sec;
sec.OP();
}

class Second
{

public:
static MyTest test;
Second()
{

}
void OP()
{
for (int i=0;i<20;i++)
{
test.AddTail(i);
}
cout<<test;
}
};

不要把MyTest test定义成static 要不就不要再类里访问static成员的函数

1.第一行包含头文件,把扩展名写上吧
#include <iostream.h>
2.把static去掉
3.干嘛定义个namespace?然后后面也不用,删了吧

然后运行就没问题了

静态类出问题了,static去掉就可以了