세상을 이롭게

c2678 이항'<':왼쪽 피연산자로 'const_Ty' 형식을 사용하는 연산자가 없거나 허용되는 변환이 없습니다. 본문

C,C++

c2678 이항'<':왼쪽 피연산자로 'const_Ty' 형식을 사용하는 연산자가 없거나 허용되는 변환이 없습니다.

2022. 2. 16. 17:55

set 을 사용하려 하였고, 자체적으로 선언한 struct 를 사용하는 과정에서 Insert 시 나타난 문제이다.

결론은 내가 선언한 struct 의 인자를 비교하여 넣을지 말지에 대한 부분 때문에 operator 연산자를 재정의 해주는 것을 하지 않았기 때문이다.

operator를 재정의 해주어 컴파일러에게 헷갈리지 않게 알려주면 제대로 동작한다.

https://stackoverflow.com/questions/5816658/how-to-have-a-set-of-structs-in-c

 

How to have a set of structs in C++

I have a struct which has a unique key. I want to insert instances of these structs into a set. I know that to do this the < operator has to be overloaded so that set can make a comparison in or...

stackoverflow.com