Fedora Linux Support Community & Resources Center
  #1  
Old 4th April 2011, 04:46 PM
Galvin Tjime Offline
Registered User
 
Join Date: Apr 2008
Location: Cement Cornfield, OH
Posts: 65
windows_7ie
Help Needed with Function Reference Variables (C++)

Hello all,

I have recently decided to work on a program to do some calculations for mining in a game and I, in an attempt to make my code more readable, have decided to try and use reference variables for the first time in a function. I am currently coding using Visual C++ 2010 Express (I normally do it in Gedit under Fedora but the person who I am co-writing the code with only uses Windows) and it keeps yelling at me about how there are too many arguments in the function call when I try to input data into the function.

If someone could please help me and tell me what I am doing wrong, I would be most appreciative.

Code:
Function:

double set_divisors(double& veld, double& scor, double& pyro, double& plag, double& omber, double& kern, double& jasp)
{
	double divisors[6];

	divisors[0] = veld;
	divisors[1] = scor;
	divisors[2] = pyro;
	divisors[3] = plag;
	divisors[4] = omber;
	divisors[5] = kern;
	divisors[6] = jasp;

	return divisors[6];
}

Function Call:

set_divisors(1000, 833, 844, 256, 307, 386, 269);  //This is where the error occurs
Reply With Quote
  #2  
Old 4th April 2011, 05:46 PM
pforsell's Avatar
pforsell Offline
Registered User
 
Join Date: Mar 2011
Posts: 39
linuxchrome
Re: Help Needed with Function Reference Variables (C++)

Your divisors[] array is too small, you declare it to hold 6 double values but you try to use 7 elements, number 0 is the first, number 6 is the seventh.

What is the point of the function? In its current form it only tries to return the 7th element in the array (a single double value). If you wish to return the whole array, either pass a double pointer to some array as an argument to the function, or change the return type to double* and malloc some storage for your newly created array.

The arguments as reference make no sense in this context since you are not modifying them, but this is just a sample code to illustrate the point where the error happens, right?

There are much nicer container types available in C++, may I suggest you look past simple arrays.
__________________
My posts are a work of fiction. Everything I write is an opinion, a joke, or both. Do not follow my advice.

F14: Dell Latitude D630 Core2Duo 2GHz 4GB
F14 x64: HP i7 3GHz 12GB
#317797

Last edited by pforsell; 5th April 2011 at 03:42 PM.
Reply With Quote
Reply

Tags
function, needed, reference, variables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell variables BLooDMaN Using Fedora 3 19th April 2007 02:27 PM
Reference Help Needed Tahir Using Fedora 0 19th April 2007 08:23 AM
Using variables in yum pingoomax Using Fedora 1 23rd February 2007 05:47 PM
Reference LinuXnooB Fedora Focus 4 3rd February 2005 04:34 AM


Current GMT-time: 21:14 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat