+ 3
Issue with referencing a value [ Solved ]
I created two classes one Super or base class and one derived. I want to pass a value to the derived class's level property but my function returns a memory address. If you know what I did wrong, I would appreciate a hint on how the solve the issue. here is the code. https://code.sololearn.com/c83Sbe5wckt9/?ref=app
8 Respuestas
+ 7
I fixed it for you, your setLevel function was wrong:
https://code.sololearn.com/cglcY259paM4/?ref=app
+ 8
You made some mistakes with the setlevel() method in derived class. It should be:
class LightningDragon:public Dragon {
public:
void setLevel(int l){
level = l;
}
LightningDragon(int l){
setLevel(l);
}
// ...
};
+ 5
You declared int setLevel inside the constructor, and in the function lower down you declared a level variable inside setLevel(), instead of setting the value to the "level" member.
+ 2
@Karl T
Thank you!
I am reviewing the code.
Where is the issue with the setLevel(); ?
@Hatsy answered it already
+ 2
@Hatsy
Thank you!
it makes sense a set function should not return the value.
Then it must have been returning addresses or random values
+ 1
The code is large, so I left comments in the main on the getLevel(); function.
The function giving me trouble.
+ 1
I am trying the edit the set and get functions to get the result I want.
+ 1
Lol
Thanks again,
spent a lot of time trying to find a solution.
I did not see the extra " int" derailing the function.