c++ coding error w/ classes...frustrated!

  • jlazzaro
  • Born
  • Born
  • jlazzaro
  • Posts: 4

Post 3+ Months Ago

there is probobly a real easy solution to this, but im just not seeing it. Here is the code:

const int arrSIZE=50;

class Account {

private:
int init;
public:
Account() : init(0) {}
int isEmpty();
};

int Account::isEmpty() {

if (init == 0)
return 1;
else
return 0;
}

int main() {

Account user[arrSIZE];

if (user[0].isEmpty == 1) {
cout << "create the account";
}
getch();
return 0;
}

i dont know if i have to typecast the value being returned or what, but here are the errors:

error C2446: '==' : no conversion from 'const int' to 'int (__thiscall Account::*)(void)'

error C2040: '==' : 'int (__thiscall Account::*)(void)' differs in levels of indirection from 'const int'

can someone help me out? TIA!
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Working ok to me. I had to add a couple of libraries, ncurses and STDC++. Tested on Linux.

Code: [ Select ]
#include <curses.h>
#include <iostream.h>

const int arrSIZE=50;

class Account {

    private:
        int init;
    public:
        Account() : init(0) {}
        int isEmpty();
};

int Account::isEmpty() {

    if (init == 0)
        return 1;
    else
        return 0;
}

int main() {

    Account user[arrSIZE];

    if (user[0].isEmpty() == 1) {
        cout << "create the account";
    }
    getch();
    return 0;
}
  1. #include <curses.h>
  2. #include <iostream.h>
  3. const int arrSIZE=50;
  4. class Account {
  5.     private:
  6.         int init;
  7.     public:
  8.         Account() : init(0) {}
  9.         int isEmpty();
  10. };
  11. int Account::isEmpty() {
  12.     if (init == 0)
  13.         return 1;
  14.     else
  15.         return 0;
  16. }
  17. int main() {
  18.     Account user[arrSIZE];
  19.     if (user[0].isEmpty() == 1) {
  20.         cout << "create the account";
  21.     }
  22.     getch();
  23.     return 0;
  24. }


# gcc test.cpp -lncurses -lstdc++
  • jlazzaro
  • Born
  • Born
  • jlazzaro
  • Posts: 4

Post 3+ Months Ago

after i ran what i posted, it worked for me too...lemme post the complete program, i was trying to strip it down to the stuff that wasnt working...I ran this a bunch of times and was still getting the error i was getting before:

Code: [ Select ]
#include<iostream>
#include<iomanip>
#include<string>
#include<conio.h>
#include<process.h>
#include<iomanip>

using namespace std;

const int arrSIZE=50;
const int msgSIZE=100;

class Account {
    
private:
    int inbox, sent, msgIndex, init;
    string username, password;
    string inboxMSG[msgSIZE];
    string sentMSG[msgSIZE];

public:
  Account() : init(1), inbox(0), sent(0) {}
    void mainMenu();
    void createAccount(string, string);
    int isEmpty() {return init;}
    string getUser() {return username;}
};

void Account::createAccount(string setUser, string setPass) {

    username = setUser;
    password = setPass;
    init = 0;
    inbox, sent, msgIndex = 0;
}

void Account::mainMenu() {

    system("cls");
    cout << "+-------------------------------------------------+" << endl;
    cout << "| Inbox: -- | Sent Items: -- | Deleted Items: -- |" << endl;       
    cout << "|-------------------------------------------------|" << endl;   
    cout << "| You are logged is an [" << username << "]       |" << endl;
    cout << "|-------------------------------------------------|" << endl;
    cout << "| C=Compose I=Inbox S=Sent D=Deleted L=Logout |" << endl;
    cout << "+-------------------------------------------------+" << endl << endl;
}

void createAccount(Account []);
void defaultMenu();
void loginAccount();

int main() {

    char choice;
    Account user[arrSIZE];

    do {

        defaultMenu();

        cout << "Selection: ";
        cin >> choice;

        choice = tolower(choice);

    } while (choice != 'c' && choice != 'l');

    switch (choice) {

    case 'c':
        createAccount(user);

    case 'l':
        loginAccount();
    };

    getch();
  return 0;
}

void defaultMenu() {

    system("cls");
    cout << "+-------------------------------------------------+" << endl;
    cout << "| Inbox: -- | Sent Items: -- | Deleted Items: -- |" << endl;       
    cout << "|-------------------------------------------------|" << endl;   
    cout << "| You are not logged in!             |" << endl;
    cout << "|-------------------------------------------------|" << endl;
    cout << "|    C=Create Account     L=Login    |" << endl;
    cout << "+-------------------------------------------------+" << endl << endl;
}

void createAccount(Account user[arrSIZE]) {

    string username, password;
    system("cls");

    cout << "Creating new Account..." << endl << endl;

        cout << "Enter username: ";
        getline(cin, username);

        cout << "Enter password: ";
        getline(cin, password);

        for (int i = 0; i <= arrSIZE; i++) {

            if (user[i].isEmpty == 1) {

                user[i].createAccount(username, password);
                i = arrSIZE;

                cout << "\n\nAccount " << username << " has been created, press any key to continue...";
                getch();
            }
        }
}

void loginAccount() {

    string username, password;
    system("cls");

    cout << "Logging into Account..." << endl << endl;
    cout << "Enter username: ";
  getline(cin, username);
    cout << "Enter password: ";
  getline(cin, password);

}
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<string>
  4. #include<conio.h>
  5. #include<process.h>
  6. #include<iomanip>
  7. using namespace std;
  8. const int arrSIZE=50;
  9. const int msgSIZE=100;
  10. class Account {
  11.     
  12. private:
  13.     int inbox, sent, msgIndex, init;
  14.     string username, password;
  15.     string inboxMSG[msgSIZE];
  16.     string sentMSG[msgSIZE];
  17. public:
  18.   Account() : init(1), inbox(0), sent(0) {}
  19.     void mainMenu();
  20.     void createAccount(string, string);
  21.     int isEmpty() {return init;}
  22.     string getUser() {return username;}
  23. };
  24. void Account::createAccount(string setUser, string setPass) {
  25.     username = setUser;
  26.     password = setPass;
  27.     init = 0;
  28.     inbox, sent, msgIndex = 0;
  29. }
  30. void Account::mainMenu() {
  31.     system("cls");
  32.     cout << "+-------------------------------------------------+" << endl;
  33.     cout << "| Inbox: -- | Sent Items: -- | Deleted Items: -- |" << endl;       
  34.     cout << "|-------------------------------------------------|" << endl;   
  35.     cout << "| You are logged is an [" << username << "]       |" << endl;
  36.     cout << "|-------------------------------------------------|" << endl;
  37.     cout << "| C=Compose I=Inbox S=Sent D=Deleted L=Logout |" << endl;
  38.     cout << "+-------------------------------------------------+" << endl << endl;
  39. }
  40. void createAccount(Account []);
  41. void defaultMenu();
  42. void loginAccount();
  43. int main() {
  44.     char choice;
  45.     Account user[arrSIZE];
  46.     do {
  47.         defaultMenu();
  48.         cout << "Selection: ";
  49.         cin >> choice;
  50.         choice = tolower(choice);
  51.     } while (choice != 'c' && choice != 'l');
  52.     switch (choice) {
  53.     case 'c':
  54.         createAccount(user);
  55.     case 'l':
  56.         loginAccount();
  57.     };
  58.     getch();
  59.   return 0;
  60. }
  61. void defaultMenu() {
  62.     system("cls");
  63.     cout << "+-------------------------------------------------+" << endl;
  64.     cout << "| Inbox: -- | Sent Items: -- | Deleted Items: -- |" << endl;       
  65.     cout << "|-------------------------------------------------|" << endl;   
  66.     cout << "| You are not logged in!             |" << endl;
  67.     cout << "|-------------------------------------------------|" << endl;
  68.     cout << "|    C=Create Account     L=Login    |" << endl;
  69.     cout << "+-------------------------------------------------+" << endl << endl;
  70. }
  71. void createAccount(Account user[arrSIZE]) {
  72.     string username, password;
  73.     system("cls");
  74.     cout << "Creating new Account..." << endl << endl;
  75.         cout << "Enter username: ";
  76.         getline(cin, username);
  77.         cout << "Enter password: ";
  78.         getline(cin, password);
  79.         for (int i = 0; i <= arrSIZE; i++) {
  80.             if (user[i].isEmpty == 1) {
  81.                 user[i].createAccount(username, password);
  82.                 i = arrSIZE;
  83.                 cout << "\n\nAccount " << username << " has been created, press any key to continue...";
  84.                 getch();
  85.             }
  86.         }
  87. }
  88. void loginAccount() {
  89.     string username, password;
  90.     system("cls");
  91.     cout << "Logging into Account..." << endl << endl;
  92.     cout << "Enter username: ";
  93.   getline(cin, username);
  94.     cout << "Enter password: ";
  95.   getline(cin, password);
  96. }
  • jlazzaro
  • Born
  • Born
  • jlazzaro
  • Posts: 4

Post 3+ Months Ago

if forgot to add () after user[i].isEmpty. :evil: damn programming!
  • dr_geek
  • Beginner
  • Beginner
  • User avatar
  • Posts: 62
  • Loc: london town

Post 3+ Months Ago

better to use a bool -- code is cleaner + you can spot errors easier:

class Account {
private:
int init;

public:
Account() : init(0) {}
bool isEmpty(); { return (init == 0); }
};


int main() {

Account user[arrSIZE];

if ( user[0].isEmpty() ) { cout << "create the account"; }
getch();
return 0;
}

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: Liamw411 and 127 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.