R
redriver
Because my english is very poor,so i give my program as follow:
////////////////////////////////////////////////////////////////////////////////////
one.hpp:
#include <iostream>
#ifndef TEST
#define TEST "The first print()"
inline void print()
{
std::cout<<TEST<<std::endl;
}
#else
#undef TEST
#define TEST "the second print()"
inline void print()
{
std::cout<<TEST<<std::endl;
}
#endif /*TEST*/
///////////////////////////////////////////////////////////////////////////////////////////////////
two.hpp:
#define TEST "none"
/////////////////////////////////////////////////////////////////////////////////////////////////
unit1.cpp:
#include "one.hpp"
#include "two.hpp" //attention about sequence of two headers
void doSomething()
{
print();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
unit2.cpp
#include "two.hpp"
#include "one.hpp" //attention about sequence of two headers
int main()
{
print();
}
what we can see there are two "print()"defined,and all in the globe
namespace and
why there is no error about redefine "print()"?
////////////////////////////////////////////////////////////////////////////////////
one.hpp:
#include <iostream>
#ifndef TEST
#define TEST "The first print()"
inline void print()
{
std::cout<<TEST<<std::endl;
}
#else
#undef TEST
#define TEST "the second print()"
inline void print()
{
std::cout<<TEST<<std::endl;
}
#endif /*TEST*/
///////////////////////////////////////////////////////////////////////////////////////////////////
two.hpp:
#define TEST "none"
/////////////////////////////////////////////////////////////////////////////////////////////////
unit1.cpp:
#include "one.hpp"
#include "two.hpp" //attention about sequence of two headers
void doSomething()
{
print();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
unit2.cpp
#include "two.hpp"
#include "one.hpp" //attention about sequence of two headers
int main()
{
print();
}
what we can see there are two "print()"defined,and all in the globe
namespace and
why there is no error about redefine "print()"?