Why do I get error "reference to non-static member function must be called":
<source>:35:19: error: reference to non-static member function must be called
list_.front().Set<Flags::First>(true);
~~~~~~~~~~~~~~^~~
<source>:40:10: note: in instantiation of member function 'List<int>::Set' requested here
list.Set();
^
<source>:13:8: note: possible target for call
void Set(bool value) {
^
1 error generated.
Compiler returned: 1
when I try to compile this code with clang 7.0.0?
#include <iostream>
#include <list>
using namespace std;
enum class Flags : uint8_t {
First = 1,
Second = 2
};
class Header {
public:
template <Flags flag>
void Set(bool value) {
flags_ = static_cast<Flags>(
value
? (static_cast<uint8_t>(flags_) | static_cast<uint8_t>(flag))
: (static_cast<uint8_t>(flags_) & (~static_cast<uint8_t>(flag))));
}
private:
Flags flags_{};
};
template <class T>
class List {
public:
void Set();
private:
std::list<Header> list_;
};
template <class T>
void List<T>::Set() {
list_.front().Set<Flags::First>(true);
}
int main() {
List<int> list;
list.Set();
return 0;
}
See here: https://godbolt.org/z/KXttBb