Solved

Class void function not accepting parameter

Posted on 2003-12-10
8
300 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…

773 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