64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class a{
public:
a(int x){
b=x;
}
a operator ++(int){
a temp(*this);
(this->b)+=1;
return temp;
}
int b;
a test(){
a m((*this).b+1);
return m;
}
};
int main(){
a x(3);
cout<<((x++)++).b; //此地方问题
(x++)=9;
cout<<x.b<<endl;
cout<<"***********";
x=9;
cout<<(x.test()).b;
(x.test())=4; //此地方也纠结
return 0;
}
上面举例不恰当:
zhixia@zhixia-PC ~/projects
$ cat t.c
#include <stdio.h>
#include <stdlib.h>
struct A
{
int i;
A& operator=(int i)
{
return *this;
}
};
A fun()
{
A a;
a.i = 10;
return a;
}
int main()
{
fun() = 1;
return 0;
}
zhixia@zhixia-PC ~/projects
$ gcc t.c
t.c:7: error: expected specifier-qualifier-list before 'A'
t.c:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fun'
t.c: In function 'main':
t.c:20: error: lvalue required as left operand of assignment
zhixia@zhixia-PC ~/projects
$ cp t.c t.cpp
zhixia@zhixia-PC ~/projects
$ g++ t.cpp
zhixia@zhixia-PC ~/projects
$
$ cat t.c
#include <stdio.h>
#include <stdlib.h>
struct A
{
int i;
};
A fun()
{
A a;
a.i = 10;
return a;
}
int main()
{
(fun()).i = 1;
return 0;
}
zhixia@zhixia-PC ~/projects
$ gcc t.c
t.c:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fun'
t.c: In function 'main':
t.c:16: error: request for member 'i' in something not a structure or union
zhixia@zhixia-PC ~/projects
$ cp t.c t.cpp
zhixia@zhixia-PC ~/projects
$ g++ t.cpp
zhixia@zhixia-PC ~/projects
$
c的标准不要用在c++中。。。。