Thread: working with a class function

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    Question working with a class function

    I get an error message that some kind of structure is needed to the left of the period in

    Code:
    cout<<Joe.range();
    Code:
    //.h file
    
    class Human
    {
    public:
    	Human(int HumanX=30) {}
       ~Human() { cout<<"A human ceases to exist."; }
       int range(HumanX) {return HumanX;};
    };
    
    
    void rooms(int room)
    {
    if (room==1)
    {
    Human *Joe = new Human();
    
    cout<<Joe.range();
    }
    }
    Code:
    //main file
    
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    #include <stdlib.h>
    #include <conio>
    #include <time>
    #include <ctype>
    #include <rooms>
    
    int end_game=0;
    int room=1;
    
    int main ()
    {
    	time_t seconds;
    	time(&seconds);
    	srand((unsigned int) seconds);
       textcolor(LIGHTCYAN);
    do
    {
       rooms(room);
    }
    	while(end_game!=1);
       getch();
       return 0;
    }
    AIM: MarderIII

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Use either of the following for pointers to classes :

    1. Joe->range(); //Short-hand method
    2. (*Joe).range();

    I'm not going to comment on the rest of your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Callback function as class method
    By schifers in forum Windows Programming
    Replies: 39
    Last Post: 05-19-2008, 03:02 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM