小编Joh*_*Elk的帖子

错误 c2373 使用模板类重新定义不同的类型修饰符

我编写了一个模板Interval类,我想将其用作数字间隔的容器。由于我想迭代此类中实际ItervalIter包含的元素,因此我添加了一个模板友元类。

当我在 Linux 上使用 编译项目以及gcc在 MacOS 上使用 编译项目时clang,一切都编译得很好,没有警告。当我在 Windows 上使用 进行编译时msvc,出现以下错误消息:

C2373 'utils::Interval<T>::begin': redefinition. The type modifiers are different
C2447 '{': missing function header (old-style formal list?)
C2373 'utils::Interval<T>::end': redefinition. The type modifiers are different
C2447 '{': missing function header (old-style formal list?)
Run Code Online (Sandbox Code Playgroud)

我简化了该类的实现Interval,以获得以下MRE

间隔.h

#pragma once
#ifndef INTERVAL_H_INCLUDED
#define INTERVAL_H_INCLUDED

namespace utils {

    template <class T> class IntervalIter;

    //-----------------------------------------------------------------------------
    // Interval
    //-----------------------------------------------------------------------------

    template <class …
Run Code Online (Sandbox Code Playgroud)

c++ templates constants visual-c++ c++03

5
推荐指数
0
解决办法
549
查看次数

标签 统计

c++ ×1

c++03 ×1

constants ×1

templates ×1

visual-c++ ×1