How does rhs work?

The compiler doesn’t know that rhs stands for “right hand side”, and in fact the name of that variable can be anything you like. The compiler “knows” how to format this because the syntax of operator= requires it to be this way. The language defines the usage of this operator to take the form: The code above calls A::operator=(const &other) against … Read more

What does |= mean in c++

a |= b; is just syntactic sugar for a = a | b;. Same syntax is valid for almost every operator in C++. But int i |= 5; is an error, because in the definition line you must have an initialisation, that is an expression that does not use the variable being declared. is valid and will give value … Read more

What is the C equivalent to the C++ cin statement?

cin is not a statement, it’s a variable that refers to the standard input stream. So the closest match in C is actually stdin. If you have a C++ statement like: a similar thing in C would be the use of any of a wide variety of input functions: See an earlier answer I gave to a question today … Read more

prototype for “….” does not match any in class “…”

Your header file with class student_Example doesn’t promise a constructor. (And seems to be missing and #endif) While we are there we can use an member initialiser list in the constructor Edit: Note that student_Example(char nam, int marc1, int marc2) is a declaration that you will define a constructor taking a char and two ints., … Read more

Integer to hex string in C++

Use <iomanip>‘s std::hex. If you print, just send it to std::cout, if not, then use std::stringstream You can prepend the first << with << “0x” or whatever you like if you wish. Other manips of interest are std::oct (octal) and std::dec (back to decimal). One problem you may encounter is the fact that this produces … Read more

c++ error: invalid types ‘int[int]’ for array subscript

C++ inherits its syntax from C, and tries hard to maintain backward compatibility where the syntax matches. So passing arrays works just like C: the length information is lost. However, C++ does provide a way to automatically pass the length information, using a reference (no backward compatibility concerns, C has no references): Demonstration: http://ideone.com/MrYKz Here’s … Read more

Adding message to assert

You are out of luck here. The best way is to define your own assert macro. Basically, it can look like this: This will define the ASSERT macro only if the no-debug macro NDEBUG isn’t defined. Then you’d use it like this: Which is a bit simpler than your usage since you don’t need to … Read more