No match for ‘operator<<’ (probably due to my version of c++/gcc?)

I’m a C++ newbie. I’ve tried to set up NetBeans and run a c++ program in my MacBook Air via virtual machine (UTM) lately. It works well in my company’s Linux desktop, but somehow it just doesn’t work in my virtual Linux. The source code is the same in these two platforms, but they have… Read More No match for ‘operator<<’ (probably due to my version of c++/gcc?)

Operator overload for ostream not working with user defined class

I have this simple program and when i try to cout << 75.0_stC ; i have multiple errors and i don’t know why.This things only happen when i pass my temperature object via reference. class temperature { public: long double degrees; temperature(long double c): degrees{c}{} long double show()const {return degrees;} }; temperature operator"" _stC(long double… Read More Operator overload for ostream not working with user defined class

C++ higher order functions: different results when declaring multiple functions

I was plying with higher order functions, and I started getting different results when I created two instances and assigning them to variables. I reduced the issue to the following example: #include <iostream> using ColorGetter = int(*)(void); auto paint(const ColorGetter &f) { return [&]() { return f(); }; } int colorA() { return 10; }… Read More C++ higher order functions: different results when declaring multiple functions

C++ Can not manage to display the class datatype array

This is the code I wrote, total beginner #include <iostream> #include <cstring> using namespace std; class Person { public: string ID; string name; string surname; string department; string email; public: //get and set functions for ID, Name, Surname, Department, Email properties string getID() { return this->ID; }; void setID(string _ID) { this->ID = _ID; };… Read More C++ Can not manage to display the class datatype array

Why does operator==(std::variant<T, U>, T) not work?

Consider the following: #include <iostream> #include <variant> int main () { std::variant<int, float> foo = 3; if(foo == 3) { std::cout << "Equals 3\n"; } } Godbolt demo here This does not compile because of the foo == 3: <source>:7:12: error: no match for ‘operator==’ (operand types are ‘std::variant<int, float>’ and ‘int’) 7 | if(foo… Read More Why does operator==(std::variant<T, U>, T) not work?