0

So, long story short: I started using "devkitPro", which is a C++ library, however I never coded with C++ before, but I did with C#, which is pretty similar to, so I started learning a little about C++, tried to code a prototype button class, created a boolean method that would return true if the clicked area was colliding with it, then I recieved this error when I tried to compile the code I wrote.

So as normally, I did what every person would do after seeing a error: I google it. Apparentaly this error is caused because of syntax mistake. So far, so good, had dealt with it before, not too much of a problem. However, the problem is that the error points to a goddamn "}", that if I remove will cause another error because the "}" is required to end a method. I tried and tried many different ways to solve this but I simply can't find the problem. Here is the script with the problem (error points to line 20)

#include <nds.h>
#include <nds/arm9/video.h>
#include <nds/arm9/sprite.h>
#include <stdio.h>
#include <string>
using namespace std;

class Button{
    public:
        string name;
        uint posX;
        uint posY;
        uint sizX;
        uint sizY;
        bool show;
    
    bool pressed(uint touchX, uint touchY)
    {
        return (show == true && posX + sizX > touchX && posY + sizY > touchY && posX < touchX + 1 && posY < touchY + 1);
    } //the error message points to this line
}

Or more expecificaly this part of the code

bool pressed(uint touchX, uint touchY)
{
    return (show == true && posX + sizX > touchX && posY + sizY > touchY && posX < touchX + 1 && posY < touchY + 1);
} //the error points to this line

So uh... anyone have any idea of what is wrong here. Thanks. I don't know much about C++ and all I know is because is similar to C#.

(Unrelated but, what is so special about the string variable type that it needs its own namespace to work propely?)

I tried to code a boolean method that returns true or false depending if your mouse cursor is colling with it, but I couldn't exactly see if it works or not because of an error I don't understand what exactly is causing.

guava
  • 11
  • 2
  • 2
    Your `class` seems to have no `;` at the end of it. This is required in C++. `class Foo { };` `uint` is also not standard. Where does that come from? As far as namespaces go, you're coming from C# where all system libraries are in namespaces, why would C++ doing something similar surprise you? Before you develop too many bad habits you should read [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Retired Ninja Jan 29 '23 at 00:39
  • Retired Ninja thanks. I asked the string namespace thing because in C# strings are included within the "system" namespace, but in C++ you need to include a separate namespace. Again, first time learning C++. Also, I wasn't referring to "using namespace std;", but the "#include " and I thougth "#include" was the C++ equivalent to C#'s "using". – guava Jan 29 '23 at 00:54
  • 1
    `#include` literally only means "insert the contents of this file here". The similarities between C# and C++ are mostly punctuation and the spelling of some keywords. Start at the beginning in a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), don't assume that things that look the same are the same, and don't guess. – molbdnilo Jan 29 '23 at 01:08
  • molbdnilo Ok then, thanks for the help. – guava Jan 29 '23 at 01:14

0 Answers0