Solved

Class void function not accepting parameter

Posted on 2003-12-10
8
321 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

729 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