2010-11-24 6 views
2

내가 로케일 측면의 사용과 문자열로 wstring의 변환을 시도하고를 보호하지만, 나는 다음과 같은 오류에 붙어있어 :'가상 문자의 표준 : CTYPE <wchar_t> :: do_narrow (wchar_t를, 문자) CONST는'

test_facet.cpp: In function ‘int main()’: 
test_facet.cpp:14: error: invalid initialization of reference of type ‘std::ctype<wchar_t>&’ from expression of type ‘const std::ctype<wchar_t>’ 
/usr/include/c++/4.4/bits/locale_facets.h:1430: error: ‘virtual char std::ctype<wchar_t>::do_narrow(wchar_t, char) const’ is protected 
test_facet.cpp:16: error: within this context 

출처 :

#include <iostream> 
#include <string> 
#include <locale> 
#include <algorithm> 

using namespace std; 

int main() 
{ 
locale loc(""); 
std::wstring Str = L"ěščřžýáíé"; 
std::string Str2; 
ctype<wchar_t> &ct = std::use_facet<std::ctype<wchar_t> >(loc); 
for(std::wstring::const_iterator It = Str.begin(); It < Str.end(); ++It) 
    ct.do_narrow(*It, 'X'); 
std::cout << Str2 <<std::endl; 
} 

누군가가 말해 수, 내가 무슨 일을 dooing 무엇입니까?

감사합니다.

답변

0

2 일 :

1) use_facet 반환에서 const 참조, 그래서 당신은 const가 아닌 하나에 할당 할 수 없습니다. 두 번째 오류 메시지 상태로

const ctype<wchar_t> &ct = .... 

2), do_narrow가 보호 외부 호출자가 접근 불가 만드는 : 그래서 CT를 선언합니다. 대신 공개 인 narrow을 사용하십시오.

+0

답장을 보내 주셔서 감사합니다. 어떻게 든 ctype의 모든 공용 회원을 놓쳤으며 보호 된 사람 만 보았습니다. – Trakhan

0

이 컨텍스트에서 do_narrow를 호출 할 수 없습니다. 클래스 ctype (및 파생 된)의 멤버 메서드 만 do_narrow를 호출 할 수 있습니다.