Re: [Dev-C++] Demystifying namespace



For what I see, your code is doing exactly the same, but without using those #defines

Maya wrote:

I want to replace the word __func__ with the word file, and you are telling me to assign the value of __func__ to the std::string variable?

Gotta check those books again, eh!

pdvz xs4all nl wrote:

You shouldn't use #defines. #defines are cross-everything, they don't care
about scope, namespaces, functions, whatever. It's just a simple global
search&replace operation performed by the preprocessor. If you want your
namespace code to work, change it to something like:

namespace foo{
   const std::string file = __func__;
   const size_t      line = __LINE__;
}
Note that I didn't test this though, but it should work (and didn't you mean
__FILE__ instead of __func__ there?)

Regards,


Paul

-----Original Message-----
From: dev-cpp-users-admin lists sourceforge net
[mailto:dev-cpp-users-admin lists sourceforge net] On Behalf Of Maya
Sent: Thursday, December 18, 2003 7:49 AM
To: C/C++ Programmers; Dev - C++
Subject: [Dev-C++] Demystifying namespace

I have a little bit of a problem with 'namespace'. Here is my problem:
namespace foo{
    #define file __func__
    #define line __LINE__
    enum error_t {one, two, three};
}
namespace foo{
   class loo{
      public:
         loo(){
            std::string f = foo::file;
            size_t l = foo::line;
            std::cout << "file: " << f << " line: " << l << std::endl;
std::cout << foo::one << foo::two << foo::three << std::endl;
         }
   };
}
These std::cout's give me a parse error, what am I doing wrong?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]