hank99
hank99

Reputation: 185

C++ errors, maybe coming from .h files, not sure

Ok, I am trying to compile a program:

g++ -std=c++0x a1test.cpp GS1Prefix.cpp EAN.cpp

But I am getting errors that I never seen before.

In file included from a1test.cpp:17:0:
EAN.h:3:25: error: âPrefixâ does not name a type
EAN.h:3:33: error: ISO C++ forbids declaration of âpâ with no type [-fpermissive]
a1test.cpp: In function âbool RegisteredTests(const Prefix*, int&, int*, int*)â:
a1test.cpp:222:68: error: no matching function for call to âisRegistered(const Prefix*&, const char [14], char [6], char [8], char [7])â
a1test.cpp:222:68: note: candidates are:
EAN.h:3:6: note: bool isRegistered(const int*, const char*, char*, char*, char*)
EAN.h:3:6: note:   no known conversion for argument 1 from âconst Prefix*â to âconst int*â
GS1Prefix.h:10:6: note: bool isRegistered(const Prefix*, int)
GS1Prefix.h:10:6: note:   candidate expects 2 arguments, 5 provided

This is just half of the errors, below i have all the .h files and a link to a1test.cpp (its a long code)

EAN.h

bool isValid(const char* str);
bool isRegistered(const Prefix* p, const char* str, char area[],char publisher[], char title[]);

GS1Prefix.h

const int MAX = 700;
struct Prefix {
    int  no;             // number of entries
    int  area[MAX];      // area elements
    char pubLow[MAX][8]; // low end of publisher range
    char pubHgh[MAX][8]; // high end of publisher range
    int  pubLen[MAX];    // no of chars in publisher string
};
bool load(const char* filename, Prefix* p);
bool isRegistered(const Prefix* p, int area);
int minNoDigits(const Prefix* p, int area);
bool isRegistered(const Prefix* p, int area, const char* publisher);

Link to a1test.cpp ->a1test.cpp

UPDATE: As suggested by remyabel, i made #include "GS1Prefix.h" after #include "EAN.h"

In file included from EAN.cpp:6:0:
EAN.h:3:25: error: âPrefixâ does not name a type
EAN.h:3:33: error: ISO C++ forbids declaration of âpâ with no type [-fpermissive]

Upvotes: 0

Views: 310

Answers (2)

ctschuster
ctschuster

Reputation: 172

Header files should include sufficient definition so that they are self-sufficient. In this case you need to supply a definition of the requisite type, Prefix. Just add the include to the top of EAN.h:

#include <GS1Prefix.h>
bool isValid(const char* str);
bool isRegistered(const Prefix* p, const char* str, char area[],char publisher[],
                  char title[]);

Then you can include EAN.h in any source file knowing that you don't have dependencies to worry about.

Upvotes: 1

user1508519
user1508519

Reputation:

Simply switch the order of your headers and your code should compile fine. Because you did not provide GS1Prefix.cpp and EAN.cpp I cannot comment on the rest of the errors (if there are any left.)

#include <cstring>

// GS1Prefix.h
const int MAX = 700;
struct Prefix {
    int  no;             // number of entries
    int  area[MAX];      // area elements
    char pubLow[MAX][8]; // low end of publisher range
    char pubHgh[MAX][8]; // high end of publisher range
    int  pubLen[MAX];    // no of chars in publisher string
};
// EAN.h
bool isValid(const char* str);
bool isRegistered(const Prefix* p, const char* str, char area[],char publisher[], char title[]);
// a1test.cpp
bool load(const char* filename, Prefix* p);
bool isRegistered(const Prefix* p, int area);
int minNoDigits(const Prefix* p, int area);
bool isRegistered(const Prefix* p, int area, const char* publisher);
// .. rest of your file

Upvotes: 2

Related Questions