gpt4 book ai didi

c++ - 在 Visual Studio 2017 中通过扩展每个参数包调用基类成员失败

转载 作者:太空宇宙 更新时间:2023-11-04 12:56:12 24 4
gpt4 key购买 nike

考虑以下代码:

class A
{
public:
void GoImpl() { cout << "A"; }
};

class B
{
public:
void GoImpl() { cout << "B"; }
};

template <class... Mixins>
class Foo : public Mixins...
{
public:
void Go()
{
int temp[] = { 0, (Mixins::GoImpl(), 0)... };
}
};

int main()
{
Foo<A, B> foo;
foo.Go(); // ERROR: illegal call of non-static member function

return 0;
}

这在 GCC 或 clang 中编译得很好,但在 Visual Studio 2017 中失败:

error C2352: 'A::GoImpl': illegal call of non-static member function

我还没有找到这方面的任何具体信息。这只是编译器中的错误(或未实现的功能),还是我遗漏了一些巫术?你能建议任何解决方法吗?我专门尝试在每个基类上调用一个基类函数。

最佳答案

作为解决方案,试试

    int temp[] = { 0, (this->Mixins::GoImpl(), 0)... };

    int temp[] = { 0, (static_cast<Mixins*>(this)->GoImpl(), 0)... };

关于c++ - 在 Visual Studio 2017 中通过扩展每个参数包调用基类成员失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46575673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com