K
Karl Heinz Buchegger
Baloff said:Hello
this code is putting our errors which are diffecult for me to fix, I
have been thinking about it for a while now...
thanks for helping
Well. Expand the macros by hand to see what you want from the compiler.
// A macro to define dummy functions:
#define DF(N) string N() { return N; }
DF(a); DF(b); DF(c); DF(d); DF(e); (f); DF(g);
so DF(a) expands to
string a()
{
return a;
}
So what does 'a' stand for. Well. a denotes a function which takes
no arguments and returns a string. As usual, when the name of a function
does not appear in an actual function call, it decays to a pointer to
that function. Thus
return a;
tries to return a pointer to function a.
But the declaration of that function says that the function returns a string.
main.cpp:9: error: conversion from `std::string (*)()' to non-scalar type `
std::string' requested
std::string (*)()
is C++ speak for: the data type is function which takes no arguments and returns
a std::string
What you probably wanted to do is to have the macro create a function
string a()
{
return "a";
}
you can do it this way:
#define DF(N) string N() { return #N; }
# applied to macro parameters is known as the 'stringize operation'. It turns
the macro parameter into a string.