1

I have something like:

#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 

and the compiler is throwing errors where PREFERENCE_PATH is used.

expecting primary expression before = token. 

These all worked when I was doing

#define PREFERENCE_PATH = ".\\Resources\\AppPreferences.txt" #define SPLASH_PATH = ".\\Resources\\Splash.png" 

What am I doing wrong?

5
  • 1
    Remove the equals symbol from the macro Commented Jan 30, 2013 at 20:08
  • 1
    Why are the equals signs there? Commented Jan 30, 2013 at 20:08
  • #define PREFERENCE_PATH = ".\\Resources\\AppPreferences.txt" This really worked? Commented Jan 30, 2013 at 20:10
  • @Falmarri, const char * path PREFERENCE_PATH; lol. I'm guessing it wasn't used. Commented Jan 30, 2013 at 20:10
  • @Falmarri = Yes the orignal way worked. I just asked the old developer of this code as it is his Commented Jan 30, 2013 at 20:11

2 Answers 2

6

Get rid of the equal signs. Preprocessor definitions don't use equal signs.

Then get rid of the pluses. String literals are concatenated when you put them side by side without a plus in between. Emphasis on literals because this is a compile-time feature that only works with double-quoted literals, as in "foo" "bar""foobar". It doesn't work with variables.

#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 
Sign up to request clarification or add additional context in comments.

1 Comment

I cannot believe I didnt see that.
-2

You can't concatenate strings (char* that is) in C++ like that...there is no + operator for them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.