2016-11-23 35 views
1

它的工作,但现在它不再工作,我不知道为什么。预期类型 - 操作员功能

我有这样的代码:

#include <string> 
#include <fstream> 
#include <sstream> 
#include <iostream> 
#include <cstddef> 
    std::string operator"" _quoted(const char* text, std::size_t len) { 
     return "\"" + std::string(text, len) + "\""; 
    } 

和编译过程中,我有这样的错误:

error: expected a type 
    std::string operator"" _quoted(const char* text, std::size_t len) { 
         ^

,这是 “”,它以红色突出显示。

我真的不明白发生了什么,以及它不再工作的原因是什么。

你能帮我吗?

谢谢

+3

你错过了'-std = C++ 11'吗? – P0W

+3

仍在编译C++ 11? –

+0

谢谢大家指出我。事实上,我的CMakeList中的选项已被删除。所以我又添加了-std = C++ 11编译选项,现在一切正常。 谢谢! – lilouch

回答

1

感谢@Pow和@Gill Bates,我能够解决这个问题。我不知道为什么我的CMakeList中的C++ 11选项已被删除。

因此,我添加了这条线,现在一切正常。

add_compile_options(-std=c++11 -stdlib=libc++) 

谢谢!