In the following code, where a literal is passed to the defined constructor, are there any errors?
struct A {
  int &a;
  A(int &b) : a(b) { }
};

int main() {
  A a(10);
  return 0;
}
Explanation
Yes, because a literal cannot be implicitly converted to a non-constant variable.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes