c++入门学习遇到的有关问题
c++入门学习遇到的问题
#include "iostream.h"
class xint
{
int x;
public:
xint(int a)
{
x=a;
}
void setx(int a)
{
x=a;
}
int getx()
{
return x;
}
void disp()
{
cout<<"x="<<x<<'\n';
}
};
//可能数据成员,可能也有函数等等,许许多多
//备注:一个类的构造函数其实就是对类的数据进行初始化
void main()
{
xint a(10);
a.disp();
a.setx(20);
int b=a.getx();
cout<<"b="<<b<<endl;
a.disp();
}
编译报错:
E:\C++习题集\practice.cpp(61) : error C2018: unknown character '0xa3'
E:\C++习题集\practice.cpp(62) : error C2065: 't' : undeclared identifier
E:\C++习题集\practice.cpp(62) : error C2146: syntax error : missing ';' before identifier 'a'
不知道为什么会出这样的错,请高手指点,感激不尽。。
------解决方案--------------------
xint a(10);
后面不是跟个非法字符吗?
#include "iostream.h"
class xint
{
int x;
public:
xint(int a)
{
x=a;
}
void setx(int a)
{
x=a;
}
int getx()
{
return x;
}
void disp()
{
cout<<"x="<<x<<'\n';
}
};
//可能数据成员,可能也有函数等等,许许多多
//备注:一个类的构造函数其实就是对类的数据进行初始化
void main()
{
xint a(10);
a.disp();
a.setx(20);
int b=a.getx();
cout<<"b="<<b<<endl;
a.disp();
}
编译报错:
E:\C++习题集\practice.cpp(61) : error C2018: unknown character '0xa3'
E:\C++习题集\practice.cpp(62) : error C2065: 't' : undeclared identifier
E:\C++习题集\practice.cpp(62) : error C2146: syntax error : missing ';' before identifier 'a'
不知道为什么会出这样的错,请高手指点,感激不尽。。
------解决方案--------------------
xint a(10);
后面不是跟个非法字符吗?