1

是否可以编写用户定义的文字而不编写using namespace xxx;. 例如<literal value><namespace>::<UDL>; _

namespace tostr
{
    std::string operator "" _UP(const char *str, unsigned long long int)
    {  //transformation goes here
    }       
}

int main(int argc, char** argv) 
{
    //using namespace tostr;    
    //std::string upperCase = "hello world.\n"_UP; //OK : Works perfectly.
    //Something like this
    std::string upperCase = "hello world.\n"tostr::_UP;  //????
}
4

1 回答 1

3

不,如果没有根据 C++14 标准第 13.5.8 节的 using 声明,则不能使用命名空间文字运算符(不知道是否存在于 C++11 中)。

如果你想限制 using 声明的效果(例如,如果你想使用来自不同命名空间的同名文字),你应该{}为此使用范围。

于 2017-08-17T13:57:00.003 回答