Inlined functions as arguments

This is a discussion on Inlined functions as arguments within the C++ Programming forums, part of the General Programming Boards category; I am attempting to inline a member function as an argument of an equation. Code: Player.hitper= ((d10.roll-1)*10)+(d10.roll-1) ; d10 is ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105

    Inlined functions as arguments

    I am attempting to inline a member function as an argument of an equation.

    Code:
    Player.hitper=((d10.roll-1)*10)+(d10.roll-1);
    d10 is a object of the class dice.
    The class to which the function belongs is as follows:


    Code:
    class dice
    {
    	public:
                           dice(int sides);
    			int numsides;
    			int roll()
    			{
    				(rand()%numsides)+1;
    			}
    };
    The error I'm receiving is as follows:
    invalid use of member (did you forget the `&' ?)
    I have tried to use the function with and without the 'return' keyword preceding the statement in the function.

    What am I doing wrong here?
    Hatman Approves!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,775
    Did you #include <cstdlib> for rand()? Of course, it looks like you should have that statement as a return statement.

    EDIT:
    Oh, but this is wrong:
    Code:
    Player.hitper=((d10.roll-1)*10)+(d10.roll-1);
    You are not calling the function. It should be:
    Code:
    Player.hitper=((d10.roll()-1)*10)+(d10.roll()-1);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Oh. That makes sense.

    I guess I was thinking that I was using it as an argument.

    Now that I'm calling the function correctly, the code complies.

    Thanks for your help.
    Hatman Approves!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  5. functions and pointer arguments
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2002, 04:04 PM

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