Hard
Consider a class Number which has one private data member int n and the following member functions
const Number Number::addInt(int i, const Number& obj)
{
Number temp;
temp.n = i + obj.n;
return temp;
}
const Number& Number::subInt(int i, const Number& obj)
{
Number temp;
temp.n = i - obj.n;
return temp;
}
Author: Abha AgrawaStatus: PublishedQuestion passed 468 times
Edit
3
Community Evaluations
Ambiguous
Auteur anonyme10/02/2025
Une fonction membre (probablement non statique sinon l'énoncé le dirait) qui s'appelle addInt sur un nombre n'a pas de raison de prendre un int en plus d'un autre nombre.
Sinon, on considère que ceci
Number num(4)
num.addInt(1, {2}).n == 3
alors qu'un appel d'une fonction membre devrait logiquement s'appliquer sur "num".
De plus, le retour de addInt est constant, ce qui ne sert à rien car il sera copié.
1
C++ error: undefined reference to `r2'1
Which of the following sets of code will cause a compile time error?3
C++ is a general-purpose programming language. It was developed in the 1970s by Bjarne Stroustrup at Bell Labs.1
What is the purpose of a static method in C++?1
What is the output of the following C++ code?1
Write a C++ program that creates an array of 10 Person objects.1
C++: what is the output of the following code? `std::cout << &obj << std::endl;`