Results 1 to 4 of 4

Thread: global function

  1. #1
    Join Date
    Apr 2007
    Beans
    235
    Distro
    Ubuntu

    global function

    Hi there, I have debugging errr... what's it called, a module?
    Anyway, it uses a global function called int2string. The thing is, whenever another err... cpp file imports "debug.h" it start complaining about int2string not being found.
    This is the error I get:

    Code:
    error: ‘string2chr’ was not declared in this scope
    debug.cpp
    Code:
    #include "debug.h"
    
    string int2string(const int& number) {
       ostringstream oss;
       oss << number;
       return oss.str();
    }
    debug.h
    Code:
    #define DEBUG
    
    #ifndef DEBUG_H
    #define DEBUG_H
    
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    
    #ifdef DEBUG
    
    /* just a helper for code location */
    #define PyDEBUGSTR (string("print('debug: ") + __FILE__ + ":" + int2string(__LINE__) + "')").c_str()
    #define LOC cout << "debug:" << __FILE__ << ":" << __LINE__ << " ";
    #define PyLOC PyRun_SimpleString(PyDEBUGSTR);
    
    /* macro for general debug print statements. */
    #define DEBUG_PRINT(text) LOC cout << text << endl;
    
    /* macro that prints a variable name and its actual value */
    #define DEBUG_VAR(text) LOC cout << (#text) << "=" << text << endl;
    
    /* python macro that prints a variable name and its actual value */
    #define DEBUG_PyRUN(text) PyLOC PyRun_SimpleString(text);
    
    /* python macro that prints an error */
    #define DEBUG_PyERR(type, text) PyLOC PyErr_SetString(type, text);
    
    #else
    
    /* when debug isn't defined all the macro calls do absolutely nothing for C++ debugging code and the same without helper for python debugging code */
    #define DEBUG_PRINT(text)
    #define DEBUG_VAR(text)
    #define DEBUG_PyRUN(text)
    #define DEBUG_PyERR(type, text) PyErr_SetString(type, text);
    
    #endif /* DEBUG */
    #endif /* DEBUG_H */
    So my question is, how do I add the global function to the header file?

  2. #2
    Join Date
    May 2007
    Location
    East Yorkshire, England
    Beans
    Hidden!

    Re: global function

    Just add the function prototype to your header file:

    Code:
    string int2string(const int& number);
    Website | Blog | The Arch Hurd Project

    If you want to ask about something I posted, send a PM, as I don't watch many threads

  3. #3
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: global function

    And remove the "using namespace std;" statement from the debug.h header file!

  4. #4
    Join Date
    Apr 2007
    Beans
    235
    Distro
    Ubuntu

    Re: global function

    Okay thanks, that didn't work last time I tried, though I didn't omit
    using namespace std;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •