Error: request for member...

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

#include <iostream>
#include "SalesDB.h"
#include <string.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using std::cout;
using std::endl;
using std::setprecision;
using std :: left;
using std:: right;
using std :: cerr;
using std :: ifstream;

SalesDB :: SalesDB ()
        {
        numSeller = 0;
        }

SalesDB :: SalesDB (char* fileName)
{
ifstream inFile;
inFile.open (fileName, ios::binary);
        if (!inFile)
        {
        cerr << "Error - unable to open accoutns file\n";
        exit(-1);
        }
        inFile.read ((char*) this, sizeof(SalesDB));

        inFile.close ();

}

void SalesDB :: print ()
{
        int i;

        cout << fixed << setprecision(2) << endl;
        cout << "Sales Database Listing" << endl << endl;

        for (i = 0; i < numSeller; i++)
        {
        Sellers[i].print();
        cout << endl;
        }
}


I have this error message:
SalesDB.cpp:46: error: request for member âprintâ in â((SalesDB*)this)->SalesDB::Sellers[i]â, which is of non-class type âcharâ

I'm new to this forum and also new to C++. The line that has the error is the one in bold. I'm not sure how to fix this. I would appreciate any help. Thank you.

It says that "Sellers" is an array of char's, which is a primary datatype in C++ and as such does not provide any members.
Last edited on
1
2
3
4
5
6
7
8
using namespace std;
using std::cout;
using std::endl;
using std::setprecision;
using std :: left;
using std:: right;
using std :: cerr;
using std :: ifstream;

That is not needed. When you type using namespace std; cout, endl, cin, etc. will be ready to use. With that sentence you "load" everything under the std namespace.
using namespace std; is ok for homework or your own test programs. But it's better to avoid those things when possible and use instead:
std::cout << ... << std::endl; std::cin>>...
etc.
Topic archived. No new replies allowed.