Compiled error: 'was not declared in this scope'

2

When compiling this code, the compiler complains about the following error:

  

error : 'content' was not declared in this scope

When it is apparently declared as an input parameter in the macro function.

#include <iostream>
#define mostrar    (contenido) cout << "Resultado  " #contenido "==" << ":" << contenido << endl;
using namespace std;



int main()
{
    int ai[] = { 2,3 };
    int zl = ai[0] + ai[1];
    mostrar(zl);

    int* pt1 = ai;
    int z3 = *pt1;
    mostrar(z3);

    int* pt2 = ai;
    int z4 = *(++pt2);
    mostrar(z4);

    int *pt3 = ai;
    int z5 = *pt3 + *(++pt3);
    mostrar(z5);



    return 0;
}
    
asked by D.Hazard 08.06.2017 в 07:15
source

1 answer

3

This is due to the fact that in the macros the definition of functions there should not be spaces between the name of the function and the list of parameters. Therefore, if the space between mostrar and (contenido) is cleared, it should work:

#define mostrar(contenido) cout << "Resultado  " #contenido "==" << ":" << contenido << endl;
    
answered by 08.06.2017 / 08:47
source