#include<iostream>
#include<string>
using namespace std;
class Str
{
public:
void f(const string& str)//如果 f("12345");会产生一个临时变量?
{
cout << static_cast<const void *>(str.c_str()) << endl;
c = str.c_str();
}
void fc(char const * ch)//静态字符串常量
{
cout << static_cast<const void *>(ch) << endl;
c = ch;
}
void p()
{
cout << static_cast<const void *>(c) << endl;
cout << c << endl;
}
char const * c;
};
int main()
{
string str = "1234";
string str1 = str;
string str2 = "1234";
const char * c = "1234";
const char * c1 = "1234";
cout << static_cast<const void *>(str.c_str()) << endl;
cout << static_cast<const void *>(str1.c_str()) << endl;
cout << static_cast<const void *>(str2.c_str()) << endl;
cout << static_cast<const void *>(c) << endl;
cout << static_cast<const void *>(c1) << endl;
Str str3;
str3.f("1234");
str3.p();
Str str4;
str4.f("12345");
str3.p();
Str str5;
str5.fc("12345");
str5.p();
Str str6;
str6.fc("12345");
str5.p();
}