64,691
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
struct code
{
code(int x):x(x){}
code(code *in_src)
{
*this = *in_src;
}
int x;
};
int main()
{
code a(1);
cout<<a.x<<endl;
code *b = new code(2);
cout<<b->x<<endl;
a = b;
cout<<a.x<<endl;//这个为什么不是cout<<a->x<<endl;
cout<<b->x<<endl;
}
class Book
{
int id;
public:
};
int main()
{
Book b;
Book *bp = new Book;
b = *bp; // 可以想办法让这句通过编译吗?通过在类中加入一些函数
return 0;
}
class Book
{
int id;
public:
};
int main()
{
Book b;
Book bp = new Book;
b = bp; // 可以想办法让这句通过编译吗?通过在类中加入一些函数
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(){
string str = "abc";
string *ps;
ps = &str; //把 str对象的地址赋值给指针ps
cout<<*ps<<endl; //这就是把指向string对象的指针对其'解引用'转换为对象str.
//结果输出 abc
}