本文介绍了从头文件调用函数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿.
我真的很努力地从头文件调用函数到我的main中.我知道它很简单,但也许有人可以指出问题所在或提出其他方法.

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>



这是我的主力.我相信问题是card.card1();



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;
      
};



这是我的头文件.

(我不需要想法或结构方面的帮助,而只需要使功能card1在我的主程序中运行的方法即可)

编译时,我收到一个错误请求"卡中的成员卡1",这是非类类型游戏()()"

谢谢.



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.

推荐答案

Game card();




to

Game card;


这篇关于从头文件调用函数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 01:25