I have a template function that works okay by itself:
// some_util_file.h
namespace ArgsUtil
{
struct Args
{
void* item;
Args* next{ nullptr };
};
template <typename Arg, typename... ArgRest>
static void PackArgs(Args* args, Arg arg, ArgRest...rest)
{
args->item = new Arg{ arg };
if constexpr (sizeof...(rest) > 0)
{
args->next = new Args{};
PackArgs(args->next, rest...);
}
}
}
// main.cpp
using namespace ArgsUtil;
int main()
{
Args* payload = new Args{};
PackArgs<int, std::string, float>(payload, 12, "hello", -412.f);
}
However, when I want to write a class to utilize these two methods, I get the unexpected end-of-file found
(C1004) error:
// some_other_file.h
using namespace ArgsUtil;
template <typename Arg, typename... ArgRest>
class PayloadPacker
{
public:
Args* payload{ nullptr };
PayloadPacker(Arg arg, ArgRest...rest) : payload(new Args{})
{
PackArgs(payload, &arg, &rest...);
}
};
For the record, if I even empty the constructor, it still gives the error. As such:
PayloadPacker(Arg arg, ArgRest...rest) : payload(new Args{})
{ }
This only doesn't cause errors:
PayloadPacker(Arg arg, ArgRest...rest)
{ }
To me, the code doesn't seem to have a dodgy part to cause problems.
I'd appreciate any hints/help and thanks in advance!
UPDATE
I just checked the same code with a compiler outside VS 2022 and it worked fine. It has something to do with MSVC or something... I submitted an issue in the Microsoft forum but I need to find a workaround to make it compile somehow.