I'm trying to write a program, which is split into two parts, and before to finish the first part I need write two classes, each consisting of a .h file and a .cpp file. This is my first time writing a program that involves multiple files. Anywho, the problem is that in my class Seller, I have a method called print, and in my class SalesDB, I have have to write a method print which involves calling Seller::print multiple times.
My program compiles fine, but doesn't build, I have the error message below.
I think the problem is my syntax, and I haven't found any solutions searching the web for the past couple days, most times it just resulted in creating more errors. Also, this is the syntax I've been told needs to be used:
arrayName[subscript].methodName(arguments); (for the line inside the for loop inside the last method of the salesDB class)
Here is my code:
Seller.h : the build error also points to this error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#ifndef SELLER_H
#define SELLER_H
class Seller
{
public:
//Data members
char name[31];
double salesTotal;
//Method prototypes
Seller();
Seller(char*, double);
char* getName();
double getSalesTotal();
void setSalesTotal(double);
void print();
};
#endif /* SELLER_H*/
|
Seller.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include "Seller.h"
#include <iostream>
#include <iomanip>
using namespace std;
/***************************************************************
FUNCTION: Seller constructor
***************************************************************/
Seller::Seller()
{
name[0] = '\0';
salesTotal = 0;
}
/***************************************************************
FUNCTION: alternate Seller constructor
***************************************************************/
Seller::Seller(char* newName, double newSalesTotal)
{
strcpy( name , newName );
salesTotal = newSalesTotal;
}
/***************************************************************
FUNCTION: getName
***************************************************************/
char* Seller::getName()
{
return name;
}
/***************************************************************
FUNCTION: getSalesTotal
***************************************************************/
double Seller::getSalesTotal()
{
return salesTotal;
}
/***************************************************************
FUNCTION: setSalesTotal
***************************************************************/
void Seller::setSalesTotal(double newSalesTotal)
{
salesTotal = newSalesTotal;
}
/***************************************************************
FUNCTION: print
***************************************************************/
void Seller::print()
{
cout<<left<<setw(30)<<name
<<right<<setw(9)<<fixed<<setprecision(2)<<salesTotal;
}
|
SalesDB.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#ifndef SALESDB_H
#include "Seller.h"
#define SALESDB_H
using namespace std;
class SalesDB
{
public:
//Data members
char dataBase[31];
int sellersTotal;
//Method prototypes
SalesDB();
SalesDB(const char*);
void print();
};
#endif /* SELLER_H*/
|
SalesDB.cpp : this one contains the error in the for loop in the method print
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "SalesDB.h"
#include "Seller.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
/***************************************************************
FUNCTION: SalesDB constructor
***************************************************************/
SalesDB::SalesDB()
{
sellersTotal = 0;
}
/***************************************************************
FUNCTION: SalesDB alt constructor
***************************************************************/
SalesDB::SalesDB(const char* pointer)
{
ifstream inFile;
inFile.open("sales.txt");
if ( inFile.fail() )
{
cout << "open for test.dat failed";
exit(1);
}
inFile.read((char*) this, sizeof(SalesDB));
inFile.close();
}
/***************************************************************
FUNCTION: print
***************************************************************/
void SalesDB::print()
{
cout<<left<<setw(30)<<"Sales Database Listing"
<<right<<setw(9)<<"Sales";
for ( int i = 0 ; i <= sellersTotal ; i ++)
{
cout<<Seller::name[i].print;
}
}
|
this is my first time posting here, so I don't know how to copy and paste my build error, so I'm gonna type most of it.
build error from seller.cpp
1 2 3 4 5 6
|
Checking dependencies
"C:\ProgramFiles(x86... some stuff about pedantic errors Wno-long-long, then lists the addresses of my object files or something
files/files/Seller.h: In member function 'void SalesDB::print()':
files/files/Seller.h: 21: error: object missing in reference to 'Seller::name;
files/files/\salesdb.cpp:74 error: from this location
Unsuccessful build
|
build error from salesDB.cpp
1 2 3 4 5 6
|
Checking dependencies
"C:\ProgramFiles(x86... some stuff about pedantic errors Wno-long-long, then lists the addresses of my object files or something
Seller.h: In member function 'void SalesDB::print()':
Seller.h: 21: error: object missing in reference to 'Seller::name;
salesdb.cpp:74 error: from this location
unsuccessful build
|
Let me know if you need anymore details! Thanks!