Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Class void function not accepting parameter

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
AlleyBoo
Asked:
AlleyBoo
  • 3
  • 3
2 Solutions
 
Arthur_WoodCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Split between Arthur_Wood and mayankeagle.
0
Technology Partners: 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!

 
Arthur_WoodCommented:
fine with me.

AW
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Please close it now.
0
 
Arthur_WoodCommented:
second the motion

AW
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now