- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试创建一个宏来删除类的复制和移动构造函数。这段代码无法在 GCC 4.8.2 上用“编译。它有什么问题?如果我将所有内容放在一行中,代码就会编译。
#define DISALLOW_COPY_AND_MOVE(ClassName) \
ClassName(const ClassName&) KEYWORD_DELETE; \ // Copy constructor
ClassName& operator=(const ClassName&) KEYWORD_DELETE; \ // Copy assignment operator
ClassName(ClassName &&) KEYWORD_DELETE; \ // Move constructor
ClassName& operator=(ClassName&&) KEYWORD_DELETE; // Move assignment operator
第二行不会发出编译器错误,但最后三行会。
KEYWORD_DELETE 只是:
#if defined CPP11
#define KEYWORD_DELETE = delete
#else
#define KEYWORD_DELETE
#endif // defined CPP11
这是输出:
In file included from ..\ObjectSlicing\src\main.cpp:5:0:
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:26:5: error: stray '\' in program
ClassName& operator=(const ClassName&) KEYWORD_DELETE; \ // Copy assignment operator
^
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:27:5: error: stray '\' in program
ClassName(ClassName &&) KEYWORD_DELETE; \ // Move constructor
^
In file included from ..\ObjectSlicing\src\__include__/animals:5:0,
from ..\ObjectSlicing\src\main.cpp:6:
..\ObjectSlicing\src\__include__/../animals/cat.h:28:5: error: stray '\' in program
DISALLOW_COPY_AND_MOVE(Cat)
^
In file included from ..\ObjectSlicing\src\__include__/animals:6:0,
from ..\ObjectSlicing\src\main.cpp:6:
..\ObjectSlicing\src\__include__/../animals/dog.h:28:5: error: stray '\' in program
DISALLOW_COPY_AND_MOVE(Dog)
^
In file included from ..\ObjectSlicing\src\main.cpp:5:0:
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:26:5: error: 'ClassName' does not name a type
ClassName& operator=(const ClassName&) KEYWORD_DELETE; \ // Copy assignment operator
^
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:27:14: error: expected constructor, destructor, or type conversion before '(' token
ClassName(ClassName &&) KEYWORD_DELETE; \ // Move constructor
^
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:28:5: error: 'ClassName' does not name a type
ClassName& operator=(ClassName&&) KEYWORD_DELETE; // Move assignment operator
^
最佳答案
您没有发现错误:程序中出现杂散的“\”
?
插入符号在错误的位置;它应该指向反斜杠:
..\ObjectSlicing\src\__rm_utilities__/__rm_utilities__.h:26:5: error: stray '\' in program
ClassName& operator=(const ClassName&) KEYWORD_DELETE; \ // Copy assignment operator
^ -- here
你不能在反斜杠连续符后面加上 //
注释;如果您想在宏中嵌入注释,您需要使用 /* */
注释并将它们放在 反斜杠之前。
关于c++ - 编译器错误 : "does not name a type" in macro when compiling with g++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25791566/
是否可以传递带有宏触发器的字符串作为宏参数?请参阅下面的示例代码: options mprint; %let string5='%abc%def%'; %macro test(string); dat
我意识到我的代码的某个部分由看起来相似的方法组组成(就像我有多个三重奏:一个辅助函数被另外两个为程序员准备的函数调用)。我正在尝试编写一个宏来为我定义这三个函数,这样我需要做的就是调用宏。但我的尝试导
这个问题在这里已经有了答案: What can you do with Lisp macros that you can't do with first-class functions? (8 个回答
在 haxe 宏中,对于每个表达式,我们可以以 http://api.haxe.org/haxe/macro/Position.html 的形式获取它的位置。 : { file:String,
如果我评价 (def ^:macro my-defn1 #'defn) 定义了一个名为“my-defn1”的宏,我可以像使用“defn”一样使用它。 但是,如果我改为求值 (if true (de
我想知道这段代码输出背后的原因。我想不出答案。 #define f(a,b) a##b #define g(a) #a #define h(a) g(a) void main() { print
我正在尝试编写一个宏,该宏扩展为具有解构的 let 形式。我的问题是我想拥有以 let 形式定义的符号列表,包括通过解构获得的符号列表。 用例 我试图排除这种行为,例如验证: (let [a (foo
这段代码: macro FL(message) return @sprintf("%s:%d | %s", @__FILE__, @__LINE__, message) # line 2 en
此宏的目的是创建一个宏,该宏为访问关联列表的某个键提供名称。 (defmacro generate-accessor (key-symbol prefix) (let ((mac-name
在mcpp.exe --help Options available with only -@std (default) option: -@compat Expand recursive ma
鉴于: (define-syntax (test stx) (syntax-case stx () [(_ body ...) (with-syntax ([body0 (pro
Doug Hoyte 在他对 Let Over Lambda 的介绍中将 symb 函数定义为使用宏进行元编程的基本实用程序: 在剪辑中: (defun mkstr (&rest args) (w
我的代码需要两种模式,debug 和 verbose。我在头文件中将它们定义为, #define verbose TRUE #define debug TRUE 到目前为止,在我的代码中,我一直在使用
Set-macro-character 有一个名为 non-terminating-p 的可选参数。好像是用来表示读完宏字符后是否要读另一个字符,但是reader algorithm似乎忽略了这个论点
我一直在搜索,但几乎找不到关于 LibreOffice Basic 的信息 我有点习惯在 excel 中编写宏,但这次需要做一个循环,直到我到达第一个空列并且它需要在 libreoffice 中。 在
我正在尝试编写一个调用某些函数的宏。这些函数只能由宏使用,因此我将它们放在包装宏的 letfn 中。伪代码: (letfn [(fn-a [] ...) (fn-b [] ...)
我发现对于任何在 clojure.tools.macro 中编写类似 defn 的宏的人来说,这将是一个很棒的工具。图书馆:name-with-attributes功能。文档字符串说: To be u
假设: (defmacro testing (&optional var) `(list 'this 'is ,@(when (consp var) `('a 'list)))
在 SBCL 中,我可以使用以下内容获取函数的文档字符串: (documentation #'mapcar t) 但是,我不明白如何获取宏的文档字符串。例如,给定宏: (defmacro with-l
想了解 undef 和将宏定义为 0 之间的区别。谢谢。 最佳答案 #define MACRO 0 定义预处理器标记 MACRO成为文字 0 #undef MACRO 删除预处理器标记 MACRO 的
我是一名优秀的程序员,十分优秀!