, 나는 다음과 같은 경우 :C++에서 "string *"을 "const string"으로 변환하려면 어떻게해야합니까? 예를 들어
void foo(string* s)
{
bar(s); // this line fails to compile, invalid init. error
}
void bar(const string& cs)
{
// stuff happens here
}
무엇 변환 호출 바이 성공하도록하기 위해 내가 필요합니까?
어떻게하면 다른 방법으로 할 수 있습니까? const string &를 string *으로 변환 하시겠습니까? – Petr
@Petr : 당신이'const' -ness를 없애 버릴 위험은 있지만, 당신이 무엇을하고 있는지 알고 있다면,'const_cast (& s)' –