gpt4 book ai didi

c++ - 调用模板方法导致 'operator<' 不匹配

转载 作者:行者123 更新时间:2023-11-30 02:20:38 25 4
gpt4 key购买 nike

<分区>

我对以下最小示例有疑问:

enum class modes_t {m1=0u, m2=1u};

class A {
public:
static inline A& get(void) noexcept{
static A inst;
return inst;
}
template<modes_t mode>
inline void start(void) noexcept {}
};

template<typename T>
class B {
public:
static inline void start(void) noexcept {
T::get().start<modes_t::m1>();
}
};

int main() {
B<A>::start();
}

如果我用 g++ v.7.3 编译它,(用 -std=c++17 和 -std=c++14)我得到以下错误:

main.cpp: In static member function ‘static void B<T>::start()’:
main.cpp:17:37: error: expected primary-expression before ‘)’ token
T::get().start<modes_t::m1>();
^
main.cpp: In instantiation of ‘static void B<T>::start() [with T = A]’:
main.cpp:22:11: required from here
main.cpp:17:23: error: no match for ‘operator<’ (operand types are ‘<unresolved overloaded function type>’ and ‘modes_t’)
T::get().start<modes_t::m1>();

所以编译器认为,行 T::get().start<modes_t::m1>();是一个小于 T::get().start 的比较和 modes_t::m1 .我应该怎么做才能告诉编译器这个表达式应该调用 start()在类里面A

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