에러모음/VS 에러

error C7510: '변수이름': 종속적 템플릿 이름은 '템플릿' 접두사와 함께 사용해야 합니다.

멜데스 2019. 8. 10. 20:08

VS2015에서 작성한 코드를 VS2017로 가져왔다.

문제가 하나 있었다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template < class _Type >
class Shared_Ptr 
{
    typedef Shared_Ptr<_Type> ThisType;
 
public:
    Shared_Ptr(void) : m_holder(MDS_NULL)
    {
    }
 
    template<class _T, class _Deleter >
    Shared_Ptr(_T* ptr, _Deleter deleter) : m_holder(MDS_NULL)
    {
        typedef DETAIL::PtrDeleterHolder<_T, _Deleter, mds::Memory::Allocator<_T> > HolderType;
        typedef mds::Memory::Allocator<HolderType> HolderAllocator;
        HolderAllocator allocator;
        this->m_holder = allocator.allocate(1);
        new(this->m_holder) HolderType(ptr, deleter);
        this->m_holder->AddRef();
    }
};
 
cs

예시코드는 VS2015에서 작성된 코드이다. 

해당코드를 VS2017에서 빌드할 경우 

error C7510: 'C_Allocator': 종속적 템플릿 이름은 '템플릿' 접두사와 함께 사용해야 합니다.

이런 메시지가 출력된다.

VS2017(세부 버전까지는 모르겠다.)에서 규칙 향상 목적으로 퍼미시브 모드에서 템플릿이라는 접두사를 붙여 명시하도록 변경되었다. 기본 수준에서는 C7510에러를 띄우게끔 적용되어있다.

여러 보안이나 수준 옵션을 건들이는 것보다는 역시 에러 부분을 죄다 바꿔먹는게 좋다. 크게 많지는 않으므로 수정을 했다. MS가 또 친절한게 에러를 뱉으면서 어떻게 하라는지 알려줬다. ('템플릿' 접두사와 함께 사용해야 합니다.)

그냥 '템플릿' 접두사와 함께 사용해야 합니다로 하지말고 'template' 접두사와 함께 사용해야 합니다. 였으면 좀 더 직관적이였을텐데 아쉽네.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template < class _Type >
class Shared_Ptr 
{
    typedef Shared_Ptr<_Type> ThisType;
 
public:
    Shared_Ptr(void) : m_holder(MDS_NULL)
    {
    }
 
    template<class _T, class _Deleter >
    Shared_Ptr(_T* ptr, _Deleter deleter) : m_holder(MDS_NULL)
    {
        typedef DETAIL::PtrDeleterHolder<_T, _Deleter, mds::Memory::template Allocator<_T> > HolderType;
        typedef mds::Memory::template Allocator<HolderType> HolderAllocator;
        HolderAllocator allocator;
        this->m_holder = allocator.allocate(1);
        new(this->m_holder) HolderType(ptr, deleter);
        this->m_holder->AddRef();
    }
};
 
cs

VS2017 버전으로 수정 후.