How Many Degrees?

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

We'll cover the following...

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.

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

All Cards
1
2
3
Missing Cards
(Drag and drop the cards in the blank spaces)

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

Access this course and 1200+ top-rated courses and projects.