How can I access / call class member function from main?

Discussion in 'C Programming' started by GogromaT, Apr 27, 2009.

  1. GogromaT

    GogromaT

    Joined:
    Mar 28, 2009
    Messages:
    3
    Hello everyone. I am new to classes, and I am kinda tuck on this homework assignment.

    I want to access class member function from main.
    And I don't know the way to write it :(
    What should I change in order for this piece to work. :hmm2:
    PROBLEM IN LINE 33

    Code:
    #include <iostream>
    using namespace std;
    
    const int SIZE=1000;
    
    class gameItem{
    private:
        int price;
    public:
        void setPrice (int);
    };
    
    void gameItem::setPrice (int x){
        price=x;
    }
    
    class DataBase{
    private:
        gameItem database[SIZE];
    public:
        void add_game(gameItem database);
    };
    
    void DataBase::add_game(gameItem database){
     cout<<"Hello Database!"<<endl;
     //Here I want to add game to the database
    };
    
    int main(){
    
    DataBase db();
    
    db().add_game(gameItem database);//[COLOR="Red"]<-- PROBLEM IN THIS LINE (line33)[/COLOR]
    
    
    return 0;
    }
    
    BTW errors are always different, from "expected primary expression before "database" to some "expected initialization before '.' token"

    please advise :bored:
    Last edited: Apr 27, 2009
    GogromaT, Apr 27, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran
    Replies:
    4
    Views:
    790
    Micah Cowan
    Jan 12, 2005
  2. zx.zhangxiong@gmail.com
    Replies:
    1
    Views:
    602
    Juan =?UTF-8?B?w4FuZ2Vs?=
    Jul 12, 2005
  3. zx.zhangxiong@gmail.com
    Replies:
    3
    Views:
    1,485
    Jonathan Mcdougall
    Jul 12, 2005
  4. aling
    Replies:
    6
    Views:
    469
    Xiaobin.Huang
    Oct 30, 2005
  5. ravi
    Replies:
    28
    Views:
    956
    Richard Heathfield
    Sep 26, 2007
Loading...

Share This Page