可能重复:
C预处理器:在#define中使用#if?
是否有任何技巧可以在定义的rhs内部使用预处理程序指令?问题是,预处理器将所有rhs折叠成一条长行.但也许有一招?
在rhs中我想要的例子是
#define MY_CHECK \
#ifndef MY_DEF \
# error MY_DEF not defined \
#endif
Run Code Online (Sandbox Code Playgroud)
?
目的是简短:使用1行快捷方式而不是多行检查序列.
我有两个int参数的各种函数(我自己编写函数和调用代码).我害怕在一些电话中混淆论证的顺序.
如果我调用一个参数序列错误的函数(所有参数都是int),我怎么能使用类型安全来让编译器警告我或者出错?
我尝试过typedef:Typedef不会触发任何编译器警告或错误:
typedef int X; typedef int Y;
void foo(X,Y);
X x; Y y;
foo(y,x); // compiled without warning)
Run Code Online (Sandbox Code Playgroud) msvc是否具有gcc({})的模拟.
我认为答案是否定的.
请注意,这是编译器功能的问题,而不是品味或风格的问题.
不是我建议任何人开始使用({})构造的问题.
对({})构造的引用是:http: //gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62,正式称为"表达式中的语句和声明".它允许将语句(如for,goto)和声明嵌入到表达式中.
如何通过索引访问$*array(或$ @)的eleent?
例如,让我们采用3元素数组和index = 1:
a=( a b c )
set -- a b c
echo ${a[1]}
b # good
echo ${*[1]}
bash: ... bad substitution
echo ${@[1]}
bash: ... bad substitution
Run Code Online (Sandbox Code Playgroud) Stroustrup在C++语言书中指出,类中定义的顺序无关紧要.
确实:
class C1 {
int foo() { return bar(); } // where is bar() ?
int bar() { return m_count; } // oh, here is bar(). but where is m_count ?
int m_count; // here is m_count. Better late than never !
}
Run Code Online (Sandbox Code Playgroud)
这编译.尽管有错误.按照承诺.到现在为止还挺好.
但是,这不编译:
class C2 {
void baz(Inner *p) {} // we were promised that order does not matter
// is Inner defined ?
struct Inner {}; // yes, Inner is define here.
};
Run Code Online (Sandbox Code Playgroud)
这看起来与Stroustrup在课堂上自由订购的承诺相矛盾.引用Stroustrup:"在类中声明的成员函数可以引用类的每个成员,就好像在考虑成员函数体之前完全定义了类".
有没有人知道ref允许C1和禁止C2的标准条款?我很好奇为什么在允许C1时不允许使用C2.可能是编译器错误与标准相矛盾吗?
Boost不提供单线程事件驱动模型,这在Unix之前普遍存在于pthreads - mainloop +"callbacks"之外,是吗?
例如,如果我想在单线程应用程序中使用boost :: message_queue,并将其与计时器和其他异步事件(mainloop)混合使用,那么boost不支持它,我是对的吗?
假设我有N个成员的课程.大多数成员都是可复制的.只有一个成员需要手动复制代码.
是否有方法以这样的方式编写复制赋值运算符,即我只为非标准成员编写代码,并让编译器为所有/其他成员生成复制代码?
如何防止意图定义继承定义的非继承方法.我被告知有诀窍表达它,但没有人能记得它.
说明.我有类的树:'Base'< - 'C'< - 'D',下面.Base定义了纯虚函数.该函数在C中重新定义,然后在D中重新定义.但该函数具有很长的参数列表.
在衍生链的某处,agrglist中存在微妙的错误,这使得D ::非继承.程序快速编译.并且在运行时调用错误的方法.
当方法是非继承时,是否存在导致编译错误的技巧.
#include <iostream>
class Base {
public:
virtual void VeryLongFunctionName(int VeryLongArgumentList) = 0;
};
class C : public Base {
public:
void VeryLongFunctionName(int VeryLongArgumentList) {
std::cout << "C::\n";
}
};
class D : public C {
public:
void VeryLongFunctionNane(int VeryLongArgumentList) { // typo is intentional. It's the point of the question.
std::cout << "D::\n";
}
};
int main() {
Base *p = new D;
p->VeryLongFunctionName(0);
// the intention is to print D::. …Run Code Online (Sandbox Code Playgroud) 在c ++中,是否可以声明内部类(CInner),使其具有外部类(COuter)作为其基类?
这个问题是关于c ++技术问题的.不是编程风格或个人喜好的问题.
这是C宏怪异问题.
是否可以编写一个以字符串常量X("...")作为参数的宏,并计算相同长度的y,以使Y的每个字符都是X的相应字符的[常量]算术表达式.
这是不可能的,对吧?
c++ ×6
bash ×1
boost ×1
events ×1
gcc ×1
inheritance ×1
macros ×1
type-safety ×1
visual-c++ ×1