Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey.
I'm really struggling with calling a function from a header file into my main. I know its quite simple but maybe someone could point out what's wrong or suggest a different method.

#include <iostream>
#include "Course.h"
using namespace std;

int main(int argc, char *argv[])
{
    
    string pname;
    char choice;
    
    
    cout << "Welcome to Blackjack!" << endl;
    cout << "Enter your player name: "; cin >> pname; cout << endl;
    cout << "Ready to play " << pname << "? Y/N" << endl;
    cin >> choice;
    
   // do
   // {
      if(choice == 'Y')
      {
        system("cls");
        cout << "---------BlackJack---------" << endl << endl;
        
        Game card();
        
        card.card1();
              
      }
      else if (choice == 'N')
      {
        system("pause");
        return EXIT_SUCCESS;
      }
      else
      {
        cout << "Please enter Y or N" << endl << endl;
        cin >> choice;
      }
   // }
   // while(choice != 'Y' || choice != 'N');
    system("PAUSE");
    return EXIT_SUCCESS;
}</iostream>


This is my main. I belive the issue is card.card1();

using namespace std;
class Game
{
      public:
      
      Game(){}
      
      Game(int irandom)
      {
              randomvalue = irandom;
      }
      
      ~Game(){}
                   
      int card1()
      {
        cout << "The value of your first card is: ";
        random();
        cout << randomvalue << endl << endl;
        return randomvalue;
        system("pause");
      }
      
      int random()
      {
      int a;
      srand(time(0));
      randomvalue=(rand()%11)+1;
      return randomvalue;
      }      
      
      protected:                
                int randomvalue;
      
};


This is my header file.

(I do not need help with the idea or structure just the method of getting the function card1 to run in my main)

When compiling I get one error "request for member 'card1' in 'card', which is of non-class type 'Game()()'

Thanks.
Posted
Updated 13-May-11 2:19am
v2

1 solution

Try modifying

Game card();

to
Game card;
 
Share this answer
 
Comments
WurmInfinity 13-May-11 8:20am    
Holy *&%£ your a genius! Thank you :D
Nithin Sundar 13-May-11 8:23am    
You're welcome! That's one way to call a default constructor with no arguments.
WurmInfinity 13-May-11 8:24am    
Lesson learnt :) Many thanks again!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900