Solved

Class void function not accepting parameter

Posted on 2003-12-10
8
276 Views
Last Modified: 2010-04-17
I have a class vendor created. I have a public function call loadmachine. Example: void Vendor::loadmachine(); I want to read in a file to Loadmachine in my main program
Example:
sodaMachine.loadmachine(ifstream& fileName).
{
   inFile.open;
}
I am getting error c2061 syntax error identifier ifstream in my vendorType.h file. The function reads void Vendor::loadmachine().  
As you can probably see, I am new to programming. I have tried just place the items from the file into the function. sodaMachine.loadmachine(cans, bottles) neither functions work.  Any assistance would be appreciated.
0
Comment
Question by:AlleyBoo
  • 3
  • 3
8 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
Comment Utility
This line, in the .h file:
Vendor::loadmachine().

means that the function loadmachine DOES NOT accept any arguments.  You cannot try to pass an argument to it.

so your attempt :

sodaMachine.loadmachine(ifstream& fileName)

does not match the declaration (since you are trying to pass an argument, where no argument is allowed)

also,  this

sodaMachine.loadmachine(cans, bottles)

is EVEN FARTHER from the declaration, since here you are trying to pass 2 arguments.

I would suggest that you go to the very basics, try to get an understanding of the fundamentals, BEFORE you attempt to modify existing code.

AW
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 250 total points
Comment Utility
Yup, many more things too.

>> sodaMachine.loadmachine(ifstream& fileName).
>> {
>>    inFile.open;
>> }

If that is your code, you really need to shape it up. You cannot define a function that way. You use object.functionname only while calling the function, not while defining. If the function is declared in the class as:

void loadmachine (ifstream &filename) ;

then define it outside the class as:

void loadmachine (ifstream &filename )
{
  ifstream.open ( "...." ) ;
  // etc etc
}

Also, the 'inFile' in your above code is not defined. The parameter is 'filename'.

The object sodaMachine can be used while calling the method, but you have to pass only one argument (since that's the way you defined it). sodaMachine.loadmachine (myfilename).

I also strongly recommend that you should first understand the calling of functions, then the concept of classes/ objects, declaring and defining member functions and calling them.

Regards,
Mayank.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Split between Arthur_Wood and mayankeagle.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
fine with me.

AW
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Please close it now.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
second the motion

AW
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countClumps  challenge 10 90
wordsWithoutList  challenge 24 73
sumHeights2  challenge 7 75
nestparen challenge 4 55
A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now