[Question] C++ hero.findNearestItem() error both with and without argument - Am i doing something wrong or is Codecombat broken?

Hello everyone!

C++, level 2. The Two Flowers

Typing hero.findNearestItem(); returns an error, tells me to put "Bronze Coin” in the parenthesis.

After i do that, it tells me, the function hero.findNearestItem(); takes no arguments.

Am i doing something wrong, or is codecombat broken?

Check images below for error message and code.

image

image

1 Like

Hi @auniv1, welcome to the Discourse! Thank you for posting and including the details of your issue.

It looks like the CodeCombat is getting confused by coin - in C++ new variables need to defined by their type at the start of a line.

I’m pretty sure CodeCombat stores findNearestItem as an object - so you’d probably want to write something like:

auto coin = hero.findNearestItem();

By declaring “auto,” this tells the compiler to determine the type of whatever’s being stored so it knows how to handle it when called in the future.

Compare this to, say, Python or JavaScript, in which variable type doesn’t need to be defined (much like in your coin = hero.findNearestItem())

Hopefully this helps to solve your problem. If you need anything else, don’t hesitate to reach out! :D

3 Likes