#define / ostream problem

Hi,

I have this #define :
#define TRACE_IT(AA) TRACE(__FILE__ , __FUNCTION__, __LINE__, AA)

With is use in several functions like this :
TRACE_IT ("some text");

TRACE is a function which looks like this :

void TRACE(const char * const file, const char * const function, long lineNumber, ostream& text1);

void TRACE (const char * const argFile, const char * const argFunction, long argLineNumber, ostream& argText1) {
cout << " " << argFile << " - " << argFunction << " - " << argLineNumber;
cout << " ";
cout << argText1;
cout << "\n";
}


On the line :
TRACE_IT ("some text");
the compiler gives an error : expected a ";"

Does anybody know what's wrong ?

I also tried it with the define like this :
#define TRACE_IT(AA) TRACE(__FILE__ , __FUNCTION__, __LINE__, << AA)
Same compile error.

In the end I wanna use it like this

TRACE_IT ("some text");
TRACE_IT("\"some text: \" << err");

Thanks.
TRACE's last parameter is of type std::ostream& but you pass in a string.
I don't think you can do that.

You may be able to do:
1
2
TRACE_IT << "some.text";
TRACE_IT << "some.text" << err;

To do this you need to define TRACE_IT as:
1
2
3
4
5
6
7
#define TRACE_IT trace(__FILE__, __FUNCTION__, __LINE__)

std::ostream& trace(const char* file, const char* function, long line)
{
    std::cout << " " << file<< " - " << function<< " - " << line << " ";
    return std::cout;
}

I haven't compiled it, but that's the idea. You should probably abstract out/parameterise the stream too.
Topic archived. No new replies allowed.