Should I move out of an std::optional or will copy elision handle it automatically?
I’m working with a function foo that returns an std::optionalstd::string. I have another function bar that calls foo, throws an exception if the optional is empty, and otherwise returns the contents of the optional.
Access a member field of a derived class from a pointer of the parent type
Let’s say I have two classes, A and B:
Unexpected result (C++)
using namespace std; #define mod 1e9+7 int main(){ cout<<mod; cout<<endl<<fixed<<mod; } Output: 1e+009 1000000007.000000 I know that in this case ,mod is a floating point number and so first one gives 1e+009 as output due to floating point precision. But then after while using fixed, why the output is not 1000000000.000000. (All necessary header files […]
Error in compiling with Class defined in Header File
I was implementing vec3 class inside my vec3.h header file and using it in another color.h file
but I am getting errors compiling my file which I can’t make any sense of.
Can someone explain me how this operator overloading (in C++ code) working?
I am a newbie in C++ programming. I am trying to understand a random c++ code. However, I am not able to understand how this operator overloading has been implemented in the code:
How to Efficiently Use std::variant for Error Handling in C++?
I’ve recently started exploring the use of std::variant
in modern C++ (C++17 and later) to handle errors and return values simultaneously from functions, somewhat similar to Rust’s Result
type. I understand the basic usage of std::variant
, but I’m looking for efficient and elegant patterns specifically tailored for error handling.
Underscore in header files in C++ does not give any error
So I have a main file and a bunch of other dependent files with their own header files. So while building it throws an error that a object which is created using another file(structure.cpp) and to make things within scope i used another header file extra.hpp with
How do I fix `The specified type does not meet the requirements of Cpp17MoveInsertable`?
I have built a custom class and followed (to the best of my knowledge) the rule of three, described in this post: /a/51864979/2184449 I have a custom definition for MyClass::~MyClass
, MyClass::operator=(MyClass mc)
and MyClass::MyClass(MyClass &mc)
.
How do I pass a value to use to select an element vector in C++?
I have this class, It contains a set of variables that represent the temperatures of countries
How to check if parameter passed to function is a Person or something else?
I am trying to have one function, where I can check if the type passed in is of class object or simply a variable datatype. Depending on the condition of this truth, I’d do something with this. I suppose my approach isn’t the best and I have some compiler error.