我是c ++的新手。我的朋友刚给我这个代码,但它没有工作并发送了许多语法错误,如:错误C2146,错误C2734,......我不熟悉,所以我认为应该更好地问堆栈溢出。 pixel.cpp:
#include<iostream>
#include"a.h"
using namespace std;
extern const unsigned uint_8 microsoftSansSerif_8ptBitmaps[];
extern const unsigned FONT_INFO microsoftSansSerif_8ptFontInfo;
extern const FONT_CHAR_INFO microsoftSansSerif_8ptDescriptors[];
int main()
{
getchar();
}
a.h:
// Font data for Microsoft Sans Serif 8pt
const unsigned uint_8 microsoftSansSerif_8ptBitmaps[] = {
0b11110000,
0b00010000,
0b00101000,
0b00101000,
0b01000100,
0b01000100,
0b01111100,
0b10000010,
0b10000010,
};
const FONT_CHAR_INFO microsoftSansSerif_8ptDescriptors[] =
{
{7, 0}, // A
};
const FONT_INFO microsoftSansSerif_8ptFontInfo =
{
2, // Character height
'A', // Start character
'A', // End character
2, // Width, in pixels, of space character
microsoftSansSerif_8ptDescriptors, // Character descriptor array
microsoftSansSerif_8ptBitmaps, // Character bitmap array
};
错误:
a.h(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
a.h(2) : error C2146: syntax error : missing ';' before identifier 'microsoftSansSerif_8ptBitmaps'
a.h(3) : error C2059: syntax error : 'bad suffix on number'
a.h(3) : error C2146: syntax error : missing '}' before identifier 'b11110000'
a.h(4) : error C2059: syntax error : 'constant'
答案 0 :(得分:2)
一些问题:
uint_8
,FONT_INFO
和FONT_CHAR_INFO
未在任何地方声明。
在自定义类型之前不必要地添加unsigned
是一个错误。
二进制文字需要在c ++ 11模式下编译,以及支持它的编译器。
要使用getchar
,您需要添加<cstdio>
。
通常,您应该将extern
声明放在.h
文件中,将定义放在.cpp
中,而不是相反。