为什么这段代码:
class A
{
public:
explicit A(int x) {}
};
class B: public A
{
};
int main(void)
{
B *b = new B(5);
delete b;
}
Run Code Online (Sandbox Code Playgroud)
导致这些错误:
main.cpp: In function ‘int main()’: main.cpp:13: error: no matching function for call to ‘B::B(int)’ main.cpp:8: note: candidates are: B::B() main.cpp:8: note: B::B(const B&)
B不应该继承A的构造函数吗?
(这是使用gcc)
我有一个文本文件,其中包含一长串条目(每行一个).其中一些是重复的,我想知道是否有可能(如果是这样,如何)删除任何重复.如果可能的话,我有兴趣在vi/vim中执行此操作.
我今天学到了C99和C++中的有向图.以下是有效的计划:
%:include <stdio.h>
%:ifndef BUFSIZE
%:define BUFSIZE 512
%:endif
void copy(char d<::>, const char s<::>, int len)
<%
while (len-- >= 0)
<%
d<:len:> = s<:len:>;
%>
%>
Run Code Online (Sandbox Code Playgroud)
我的问题是:它们为什么存在?
假设NULL在C 中始终转换为false 是否安全?
void *somePtr = NULL;
if (!somePtr) {
/* This will always be executed? */
}
Run Code Online (Sandbox Code Playgroud)
或者应该明确检查价值NULL?
为了真正符合标准,C中的所有函数(main除外)都必须有原型,即使它们只是在同一个翻译单元中定义之后才使用它们吗?
什么是域逻辑?域逻辑的Wikipedia页面重定向到业务逻辑.它们是同一个东西,如果不是,它们有什么不同?
是否有标准投诉方法来表示ANSI(C89/90)C中的字节?我知道,大多数情况下,一个字符恰好是一个字节,但我的理解是,这不能保证是这种情况.另外,在C99标准中有stdint.h,但在C99之前使用了什么?
我特别想知道8位和"字节"(sizeof(x)== 1).
是否有令人信服的理由不仅仅debug_backtrace用于确定调用方法的类,名称和参数列表?不用于调试目的.它在函数名中有"debug"这个词,这让我感觉有点脏,以这种方式使用它,但它符合我需要做的事情(一个可以从很多地方调用的函数)需要从另一个系统调用调用方法).它有效,但这仍然是个坏主意吗?如果是这样,为什么?
如果我有两个可变参数模板参数,A并且B,我如何在编译时确保所有成员 A的类型也是B(以相同顺序)子集的类型?
举例:
template<typename...A>
struct Foo {
template<typename...B>
static void bar()
{
}
}
...
Foo<Apple, Orange>:: template bar<Apple, Orange, Grape>(); // this compiles
Foo<Apple, Orange>:: template bar<Orange, Grape>(); // this doesn't
Run Code Online (Sandbox Code Playgroud) c ×5
c++ ×3
c89 ×2
c99 ×2
architecture ×1
c++11 ×1
constructor ×1
digraphs ×1
duplicates ×1
gcc ×1
inheritance ×1
null ×1
php ×1
pointers ×1
terminology ×1
types ×1
vim ×1
weakly-typed ×1