std :: remove_const는 const3800을 제거 할 수 없습니다. const char*
. 이 프로그램의'char const *'에서 const를 제거하는 방법
#include <iostream>
#include <type_traits>
#include <typeinfo>
template< typename T >
struct S
{
static void foo() {
std::cout << typeid(T).name() << std::endl;
std::cout << typeid(std::remove_const<T>::type).name() << std::endl;
}
};
int main()
{
S<char const*>::foo();
}
출력 (비주얼 스튜디오 2010) :
char const *
char const *
그리고 GCC에서 우리가 읽을 수있는 출력을
(코드 here) :PKc
PKc
다음 코드를 고려 Microsoft 컴파일러의 두 번째 줄에 char *
을 얻으 려하고 gcc의 모든 내용 (첫 줄과 다를 수 있음)을 얻으려고합니다. 내가 도대체 뭘 잘못하고있는 겁니까? char const*
을 char*
으로 변경하려면 어떻게해야하나요?
'문자의 CONST이 *'이다 const에 대한 포인터, 그것은 const 자체가 아닙니다. – Pubby
게시 한 코드는'typename std :: remove_const ... '없이 gcc에서 컴파일되지 않습니다. – Praetorian
예, gcc 컴파일러에 typename을 추가해야했습니다. gcc의 코드는 다음과 같습니다. http://ideone.com/Vd25T8 – Uri