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:
#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.
Let’s discuss this code and output together in the next lesson.