Class name not declared in this scope.

I resolved the question I was going to ask as I was typing out my question, hopefully, it'll happen again!

I'm creating a login system for practice, no encryption or anything, for calling classes from my main function. My issue is that I don't get any errors and yet the only text that appears is, "Login Practice System."
It almost seems that the function from the username class doesn't even run. Help? Thank you!


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include "username.h"

using namespace std;

int main()
{
    cout << "Login Practice System \n";
    Username uname;
    return 0;
}


username.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef USERNAME_H
#define USERNAME_H


class username
{
    public:
        uname();

    protected:

    private:
};

#endif // USERNAME_H 


username.cpp
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include "username.h"

using namespace std;

username::uname()
{
    string unin;
    cout << "Username:";
    cin >> unin;
}
Last edited on
If you want the function to run you need to call it first.

1
2
Username uname;
uname.uname();
Thank you so much! Haha I can't believe I missed that!
First: C++ is case sensitive. You have a class username, so you cannot use it as Username.

Second: In username.h: uname() is not the constructor (the name needs to be the class name). The compiler should give an error since that function does not have a return type.
Topic archived. No new replies allowed.