Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected unqualified-id [closed]

Tags:

c++

So, i have searched around for answers, and multiple people have got the same error response but i cannot see how their errors could fix my code.

I started trying out c++ yesterday, but i am experienced with mostly Python but also C#

I am making a simple contact book, just for learning. I am not done with the class or any other implementation, just need this fixed first.

the exact error is

kontaktbok.cpp:9: error: expected unqualified-id before 'public'

And the code is here

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

bool running = true;

public class Contact
{
    private:
        string firstname   = "";
        string lastname    = "";
        string phonenumber = "";

    public:
        Contact()
        {
            this.firstname = "Alfred";
        }
};

int main()
{
        cout << "Welcome to the Contact book!" << endl <<
                "Made by X";
    while (running)
    {
        cout << "1. Add contact"    << endl
             << "2. List contacts"  << endl
             << "3. Quit"           << endl;
        cout << "Choice: ";
        string mystr;
        getline(cin, mystr);
        int choice;
        stringstream(mystr) >> choice;
        switch (choice)
        {
            case 1: cout << "asd";
            case 2: cout << "asd2";
            case 3: running = false;
            default : cout << "Invalid integer";
        }
    }
    return 0;
}

Thanks in advance!

like image 340
Johan Bjäreholt Avatar asked Mar 16 '26 17:03

Johan Bjäreholt


1 Answers

public class Contact is not valid C++, use class Contact instead.

like image 99
Luchian Grigore Avatar answered Mar 19 '26 07:03

Luchian Grigore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!