views:

72

answers:

3
    #include "iostream"
    #include "string"

    using namespace std;

    #define AA(bb) \
            string(::##bb);
    int main (int argc, char *argv[])
    {

            AA(aa);
    }

This gives me a bunch of errors but I am trying to understand this error

pre.cpp:11:1: error: pasting "::" and "aa" does not give a valid preprocessing token

Any ideas?

+1  A: 

Remove the ## characters as they are not allowed in this context. ## is to concatenate bits to make a token, but :: should be one token and whatever bb is should be another, separate, token.

dash-tom-bang
+1  A: 

:: is already a separate token, you don't need the ## token-pasting operator for the code you showed.

Ben Voigt
+1  A: 

Your code makes little sense as there is no symbol aa in scope. Perhaps you trying to stringify the argument to your macro? If so, what you want is:

#define AA(bb) string(#bb)

This would then convert AA(aa) to string("aa")

R Samuel Klatchko