C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2009, 11:23 PM   #1
Registered User
 
Join Date: Nov 2007
Location: Free Country, USA
Posts: 104
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:
Quote:
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!
DarkAlex is offline   Reply With Quote
Old 11-11-2009, 11:24 PM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,352
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);
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 11-12-2009, 08:06 AM   #3
Registered User
 
Join Date: Nov 2007
Location: Free Country, USA
Posts: 104
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!
DarkAlex is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:48 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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