Like Tree1Likes
  • 1 Post By tabstop

How do i put functions within a class to a main?

This is a discussion on How do i put functions within a class to a main? within the C++ Programming forums, part of the General Programming Boards category; This is the function i want to call in my main. Code: void run_machine(Hand &hand, Deck &deck , Card &card, ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    33

    How do i put functions within a class to a main?

    This is the function i want to call in my main.

    Code:
    void run_machine(Hand &hand, Deck &deck , Card &card, int bet(void))
    {
    	Deck *test = new Deck();
    	Hand *testH = new Hand();
    	cout<<"HELLO WElCOME TO THE POKER MACHINE"<<endl;
    	cout<<"Please enter a bet......."<<endl;
    	bet();
    	test->shuffle();
    	test->dealHand();
    	testH->determineHand();
    }
    Which is in this class:

    Code:
    class pokerMachine
    {
    
    public:
    
    	// CONSTRUCTION 
    
    	// Default constructor.
    	// Summary  :  
    	pokerMachine(  );
    
    	// Copy Constructor.
    	// Summary  :  
    	pokerMachine( const pokerMachine& from );
    
    	// Destructor.
    	// Summary  :  
    	~pokerMachine( );
    
    	// METHODS 
    
    	int bet(void);
    	int payout(Hand &hand, int bet(void));
    	void run_machine(Hand &hand, Deck &deck , Card &card, int bet(void));
    
    private: 
    
    
    	// METHODS  
    
    
    	// ATTRIBUTES  
    
    
    };

    How would i declare the function in main?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Create an instance of your PokerMachine:

    PokerMachine poker_machine;

    Call appropriate method with all its parameters:

    poker_machine.run_machine(...);

    Also, why are you using new in your run_machine function? It is absolutely unnecessary and you are leaking memory.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You wouldn't declare the function in main at all. Are you asking how to call it?

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    Elysia: That sound very familiar! but when i try it i still get the same errors :/ is there anyway you could show me?

    Tabstop: Ya i meant call it not declare it, do u have any advice?

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Quote Originally Posted by lilbo4231 View Post
    Elysia: That sound very familiar! but when i try it i still get the same errors :/ is there anyway you could show me?
    I have shown you all I can with the information I have.
    I suggest you show your attempt so we can diagnose what you are doing wrong. Don't forget to post the compile errors, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by lilbo4231 View Post

    Tabstop: Ya i meant call it not declare it, do u have any advice?
    Type the name of the function, then a (, then all the parameters, then a ).

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    Code:
    int main(void)
    {
    	pokerMachine poker_machine;
    	poker_machine.run_machine(Hand &hand, Deck &deck , Card &card, bet());
    
    	return 0;
    }
    Code:
    Error	23	error C2065: 'card' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	19
    Error	21	error C2065: 'deck' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	19
    Error	19	error C2065: 'hand' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	19
    Error	16	error C2065: 'poker_machine' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	18
    Error	17	error C2065: 'poker_machine' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	19
    Error	14	error C2065: 'pokerMachine' : undeclared identifier	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	18
    Error	15	error C2146: syntax error : missing ';' before identifier 'poker_machine'	c:\documents and settings\cpts 122\my documents\visual studio 2008\projects\pokermachine\testcards\testmain.cpp	18

    Then there is some more undeclared identifiers

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    >>poker_machine.run_machine(Hand &hand, Deck &deck , Card &card, bet());
    This is not how you call a function. You should study that before doing another attempt.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    damn well now i am all confused.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Go check an online tutorial or consult a book about how to call functions. It should relieve your confusion.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    Quote Originally Posted by tabstop View Post
    Type the name of the function, then a (, then all the parameters, then a ).
    what does the a do?

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Nothing. Go learn the syntax of a function call!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by lilbo4231 View Post
    what does the a do?
    "a" is the English indefinite article, inflected for a following noun that starts with a consonant.
    AndrewHunter likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining functions below int main() - Best practices?
    By Programmer_P in forum C++ Programming
    Replies: 17
    Last Post: 12-09-2009, 01:08 PM
  2. Program skips functions in main
    By En-Motion in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2009, 08:35 PM
  3. g++ main main.cpp class.o
    By Paul22000 in forum C++ Programming
    Replies: 13
    Last Post: 05-27-2008, 12:18 PM
  4. multiple main functions
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 05-21-2008, 01:54 PM
  5. main in a class?
    By C3Pnuts in forum C++ Programming
    Replies: 3
    Last Post: 08-09-2005, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21