Thread: Very easy function call question

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    93

    Very easy function call question

    Code:
    class IOField
    {
    	private:
    			int row,
    				col;
    	protected:
    			void *data;
    			IOScreen *owner;
    			bool Ok;
    			void (*help)(IOScreen *scrPtr); 
    			bool (*isValid)(void *data, IOScreen *scrPtr);
    			int Row();
    			int Col();
    
    	public:
    			IOField(int row, int col, 
    				    void (*help)(IOScreen *) = NULL,
    					bool (*isValid)(void *, IOScreen *) = NULL)
    			        { this->row = row;
    					  this->col = col;
    						help(IOScreen);
    		
    					}
    };
    In the public constructor, how do I pass to help the pointer that is coming into the constructor which I defaulted to NULL?

    The error is on help(IOScreen) with the message

    Code:
    error C2275: 'IOScreen' : illegal use of this type as an expression

    Edit: The same with isValid, how would I pass it whatever comes in
    Last edited by INFERNO2K; 11-04-2005 at 07:12 PM.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You're passing a pointer to a function to the constructor. You need an IOScreen object to pass to the help function. Possibly, you could pass this to the constructor (although I'm not sure this is what you want to do):
    Code:
    IOField(int row, int col, void (*help)(IOScreen *) = NULL, bool (*isValid)(void *, IOScreen *) = NULL, IOScreen* ioscrObj)
    { 
      this->row = row;
      this->col = col;
      if(help)
        help(ioscrObj);
    }
    It's also a bad idea to default that function pointer to NULL unless you also check that it isn't null before calling it.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Ok thanks

    and for isValid I can do

    isValid(this->data, this->owner) ?

    Owner is a pointer to the IOScreen object

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM