Reputation: 29353
#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?
Upvotes: 2
Views: 808
Reputation: 76541
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")
Upvotes: 1
Reputation: 283624
::
is already a separate token, you don't need the ##
token-pasting operator for the code you showed.
Upvotes: 2
Reputation: 17843
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.
Upvotes: 2