c++ when to put method out side the class

Posted by user63898 on Stack Overflow See other posts from Stack Overflow or by user63898
Published on 2012-06-11T13:48:56Z Indexed on 2012/06/11 16:40 UTC
Read the original article Hit count: 184

Filed under:
|

i saw that some times in c++ applications using only namespace declarations with header and source file like this :

#ifndef _UT_
#define _UT_

#include <string>
#include <windows.h>

namespace UT 
{
    void setRootPath(char* program_path, char* file_path);
    char * ConvertStringToCharP(std::string str);
};

#endif

//and then in UT.cpp
#include "UT.h"

namespace UT 
{
    char * ConvertStringToCharP(std::string str)
    {
        char * writable = new char[str.size() + 1];
        std::copy(str.begin(), str.end(), writable);
        writable[str.size()] = '\0';  
        return writable;
    }

    void setRootPath(char* program_path, char* file_path) 
    {
        //...
    }
}

is it better then defining classic class with static methods?
or just simple class ?
dose this method has something better for the compiler linker ?

the methods in this namespace are called allot of times .

© Stack Overflow or respective owner

Related posts about c++

Related posts about namespaces