Question

I know this question has been asked a million times but I've looked at so many answers and not a single one was helpful.

Basically I'm creating a login form and I need to return a struct containing the email, password, and a boolean to tell whether to remember the login info specified.

I have a class called Database which is made up of "database.cpp" and "database.h". in the header file, I have:

public:
    typedef struct{
        QString email;
        QString password;
        bool remember;
    }LoginInfo;

    LoginInfo getLoginInfo();

Then in the source file, I have:

LoginInfo Database::getLoginInfo()
{
    LoginInfo data;
    data.email = QString("email@example.com");
    data.password = QString("test12345");
    data.remember = true;

    return data;
}

The error I seem to be getting is that I need a semicolon before "Database::getLoginInfo()" and that I have a redefinition of Database::getLoginInfo() when I only have one.

I don't know a whole lot in c++ and this is actually my first time using structs, but I have allot of programming experience from Java and Python. So being that I could still be considered a "noob" at c++, I'm sure I have left some silly mistakes in the code.

So yeah if you could help me that'd be great. But like I said, I've been trying to get this to work for about 2 hours now with no luck and I've givin' up searching.

Was it helpful?

Solution

The struct is defined as a member of the class so you need to use:

Database::LoginInfo Database::getLoginInfo()

OTHER TIPS

You need to properly scope your struct in the function definition.

Database::LoginInfo Database::getLoginInfo() {
    .
    .
    .
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top