Solved

Class void function not accepting parameter

Posted on 2003-12-10
8
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 9915039
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:Mayank S
Mayank S earned 250 total points
ID: 9919746
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:Mayank S
ID: 10319093
Split between Arthur_Wood and mayankeagle.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10322603
fine with me.

AW
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10558728
Please close it now.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10559905
second the motion

AW
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Introduction to Processes

630 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