好的,我正在尝试编译一个程序:
g++ -std=c++0x a1test.cpp GS1Prefix.cpp EAN.cpp
但是我遇到了以前从未见过的错误。
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
这只是错误的一半,下面是所有的 .h 文件和指向 a1test.cpp 的链接(它是一个长代码)
EAN.h
bool isValid(const char* str);
bool isRegistered(const Prefix* p, const char* str, char area[],char publisher[], char title[]);
GS1前缀.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);
链接到 a1test.cpp -> a1test.cpp
更新:按照remyabel的建议,我在#include "EAN.h"之后制作了#include "GS1Prefix.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]
最佳答案
只需切换 header 的顺序,您的代码就可以正常编译。因为您没有提供 GS1Prefix.cpp
和 EAN.cpp
我无法评论其余的错误(如果还有的话)
#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
关于C++ 错误,可能来自 .h 文件,不确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21493917/