I'm currently having a lot of issues in trying to create a struct in a class header file. In the public accessors & mutators its saying that the variables are 'undeclared identifiers', as well as i'm unsure of how to reference the struct array from the main .cpp file and assign variables from an opened file to the elements in the struct array.
//header file
#ifndef FOO_H
#define FOO_H
#include <string>
#include <iostream>
using namespace std;
class Foo
{
private:
struct bag
{
string name;
int amount;
enum tax { food, medicine } type;
};
public:
//Unsure about constructor with enum type
string getName() const
{ return name; }
int getAmount() const
{ return amount; }
void setItem(string);
void setAmount(int);
void setTaxCat(int);
};
static const float foodTax = .05, medicineTax = .04;
#endif
//Implementation file
#include "Foo.h"
#include <string>
using namespace std;
void Foo::setItem(string item)
{ name = item; }
void Foo::setAmount(int qty)
{ amount = qty; }
void Foo::setTaxCat(int tx)
{ type = static_cast<tax>(tx); }
//Main program
#include "Foo.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string item;
int qty;
int tx;
ifstream inputFile;
string fileName;
const in size = 20;
cout << "Enter file name: ";
getline(cin, fileName);
inputFile.open(fileName.c_str(), ios::in);
bag items[] //Unsure how to create array from the struct in the class header file
for(int index = 0; index < size; index++)
{
while(index < size && !inputFile.eof())
{
getline(inputFile, item, '#');
items[index]->setItem(item); //unsure how to send items to
getline(inputFile, qty, '#');
items[index]->setAmount(qty);
getline(inputFile, tx, '#');
items[index]->setTaxCat(tx);
}
}
inputFile.close();
return 0;
}
here's an example of the file it's referencing
Eggs#12#food
Cough Drops#2#medicine