我有类似的东西:
#define BASE_FOLDER = "Resources"
#define PREFERENCE_FILE_NAME = "AppPreferences.txt"
#define SPLASH_FILE_NAME = "Splash.png"
#define PREFERENCE_PATH = ".\\" + BASE_FOLDER + "\\" + PREFERENCE_FILE_NAME
#define SPLASH_PATH = ".\\" + BASE_FOLDER + "\\" + SPLASH_FILE_NAME
并且编译器在使用PREFERENCE_PATH时抛出错误。
expecting primary expression before = token.
这些都在我做的时候起作用
#define PREFERENCE_PATH = ".\\Resources\\AppPreferences.txt"
#define SPLASH_PATH = ".\\Resources\\Splash.png"
我做错了什么?
答案 0 :(得分:6)
摆脱等号。预处理程序定义不使用等号。
然后摆脱优势。当你并排放置字符串文字而没有加号时,它们会串联起来。强调文字,因为这是一个编译时功能,仅适用于双引号文字,如"foo" "bar"
→"foobar"
。它不适用于变量。
#define BASE_FOLDER "Resources"
#define PREFERENCE_FILE_NAME "AppPreferences.txt"
#define SPLASH_FILE_NAME "Splash.png"
#define PREFERENCE_PATH ".\\" BASE_FOLDER "\\" PREFERENCE_FILE_NAME
#define SPLASH_PATH ".\\" BASE_FOLDER "\\" SPLASH_FILE_NAME
答案 1 :(得分:-2)
你不能在C ++中连接字符串(char *),就像那样......没有+
运算符。