How Many Degrees?

Test your C++ programming skills by solving the given puzzle about constructors.

Puzzle code

Carefully read the code given below:

Press + to interact
#include <iostream>
struct Degrees
{
Degrees() : degrees_(0)
{
std::cout << "Default constructer invoked\n";
}
Degrees(double degrees) : degrees_(degrees)
{
std::cout << "Constructed with " << degrees_ << "\n";
}
double degrees_;
};
struct Position
{
Position() : latitude_{1} { longitude_ = Degrees{2}; }
Degrees latitude_;
Degrees longitude_;
};
int main()
{
Position position;
}

Your task: Guess the output

Try to guess the output of the above code. Attempt the following test to assess your understanding.

The possible console output lines are given below on the right side column. Place them in the correct sequence.

Drag and drop the cards in the blank spaces.


Let’s discuss this code and output together in the next lesson.