Define an overloaded + Operator C++

Asked

Viewed 87 times

0

I could not resolve the following question:

Fill in the Blanks to define an overloaded +Operator for the class "Test".

Test Test::______(Test obj){
___newObj;
newObj.mem=
mem__obj.mem;
return newObj;
} 

I don’t know how to fill in the spaces with the following Native Aids: Operator const Test class

Sorry, I was wrong in typing. the correct alternatives is like this: class Operator+ const+ Test

  • Are you sure this? , isn’t it crowded too much? It’s hard to understand written that way. There are 4 options and 3 gaps?

  • @bigown, I didn’t type this way, I pressed enter where I should have pressed, but everything appears in the same line. I found the answer, in the first space you type Operator+, in the second space you type Test and you put the + signal in the third space. Thank you very much for your attention and patience.

  • I’ll see if I can edit the code so it appears as it should appear

  • Yeah, I know, it’s still too crowded, there’s no spaces, there’s stuff that jumped line without making sense, I think there’s typos there, if there’s not yet it’s hard to understand. Use the {} or CTRL-K in all code

  • I typed it right, but it’s all on the same line I don’t know why.

  • I myself answered this question, as I said, in the first space if you type Operator+, in the second space you type Test and you put the + sign in the third space.

  • @bigown, when you press the edit button, the code appears in the way I typed, the spaces appear, the lines, appears correctly typed, it is not possible to see it somewhere?

Show 2 more comments

1 answer

0

Written code is hard to understand but, will That’s what you’re trying to do?

Test Test::operator+ (Test obj) const
{
 Test newObj;
 newObj.mem = obj.mem;
 return newObj;
}
  • i just tried to fill in the blanks, this is a matter of course C++ Tutorial Course from Sololearn, I finished this course and the course Ruby Tutorial Course, now I’m doing the course Swift Fundamental, i will try to find the answer to what I tried to do when I posted this question about the C course++.

  • tesseractBird, this is the answer: in the first space you type Operator+, in the second space you type Test and in the last space you type only +.

  • @bigown, please tell me your opinion about my latest comments.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.