|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 小剑剑 于 2016-8-10 08:37 编辑
一共三个文件很简单的代码
文件3的其中一句有错但不理解
开始我以为是优先级问题,但b<<(a<<cout);没有出错,证明优先级没问题,那为什么多了一个c就出错了呢??
文件1- #include <string>
- #include <iostream>
- #ifndef prog_h
- #define prog_h
- namespace prog
- {
- using namespace std;
- class Prog
- {
- private:
- string name;
- int cp;
- public:
- Prog();
- Prog(const int ,string const na="Ploga");
- void changep(const int);
- ostream& operator <<(ostream &os)const
- {
- os<<name<<endl;
- os<<cp<<endl;
- return os;
- }
- };
- }
- #endif // prog_h
复制代码
文件2
- #include "prog.h"
- using namespace prog;
- Prog::Prog()
- {
- name="Plorga";
- cp=50;
- }
- Prog::Prog(const int c,const string na)
- {
- cp=c;
- if (na.size()>19)
- {
- cout<<"name is too long "<<endl;
- return ;
- }
- name=na;
- }
- void Prog::changep(const int c)
- {
- cp=c;
- }
复制代码
文件3
- #include <iostream>
- #include "prog.h"
- using namespace prog;
- int main()
- {
- Prog a(1),b(2,"123"),c();
- (b<<(a<<cout));
- c<<(b<<(a<<cout));//这里会出错这里会出错这里会出错
- }
复制代码
求解,另外代码有哪里不够好的,大家请指出
|
|