October 25, 2024
Chicago 12, Melborne City, USA
templates

MSVC Error: Template class with int64_t member – 'followed by __int64 is illegal'


Working on cross compiling this FLOSS, I’m trying to compile a simple template class that uses int64_t as a template parameter, but MSVC (Visual Studio 2019) gives me errors about illegal type usage. Here’s a minimal example:

#include <cstdint>

class test_class {
public:
    template<typename T>
    class inner_class {
    private:
        T value;
    public:
        inner_class() : value(T()) {}
        bool operator==(const inner_class<T>& other) const {
            return value == other.value;
        }
    };

    inner_class<int64_t> _int64;  // Error here
};

int main() {
    test_class t;
    return 0;
}

When compiling with:

cl.exe /std:c++17 /EHsc /W4 test.cpp

I get these errors:

error C2628: 'test_class::inner_class<int64_t>' followed by '__int64' is illegal (did you forget a ';'?)
error C2208: 'test_class::inner_class<int64_t>': no members defined using this type

I’ve tried using std::int64_t explicitly and also tried creating type aliases, but still get similar errors. The code compiles fine with GCC and Clang.

Visual Studio version:

Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30156 for x64

What I’ve Tried

  1. Using explicit std:: namespace:
inner_class<std::int64_t> _int64;
  1. Using type aliases:
using int64_type = std::int64_t;
inner_class<int64_type> _int64;
  1. Adding typename keyword:
inner_class<typename std::int64_t> _int64;

All produce the same or similar errors. What am I doing wrong? Is this a MSVC-specific issue?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video