Daily C++ Interview

Sign up for free and get your C++ question every day!



How does it work?


You sign up with your e-mail address and you get a question in your mailbox every day.

A question that was asked in interviews. You try to answer the question or solve the problem. It'll stretch your skills, you will learn and grow.

Those who sign up for the PRO version will also receive detailed answers and when applicable with ready-to-run code, complexity analysis.




A sample question

What is the difference between function overloading and function overriding?

Function overriding is a term related to polymorphism. If you declare a virtual function in a base class with a certain implementation, in a derived class you can override it's behaviour in case you uses the very same signature. In case, the virtual keyword is missing in the base class, it's still possible to create a function with the same signature in the derived class, but it doesn't override it. Since C++11 there is also the override specifier which helps you to make sure that you don't mistakenly failed to override a base class function. You can find [more details here.

Function overriding enables you to provide specific implementation of the function that is already defined in its base class.

On the other hand, overloading has nothing to with polymorphism. When you have two functions with the same name, some return type, but different number or types of parameters, or qualifiers.

Here is an example for overloading based on parameters

void myFunction(int a);
void myFunction(double a);
void myFunction(int a, int b);

And here is another example based on qualifiers:

class MyClass {
public:
  void doSomething() const;
  void doSomething();
};

Or actually, it possible to overload your function based on whether their hosting objects are rvalue of lvalue references.

class MyClass {
public:
  // ...
  void doSomething() &; // used when *this is a lvalue
  void doSomething() &&; // used when *this is a rvalue
};

You can learn more about this here.


Meet Sandor, your instructor

Sandor is a senior software engineer at the world’s leading reservation platform provider, besides he is a writer, confernce speaker. He’s been a C++ engineer since 2013. Sandor has been working on C++ teams providing company-wide used APIs just as well reservation systems that most probably you already used during travelling. His passion on knowledge sharing also led him to work on the interview questions they ask from new hires.