如何查看预处理的结果?例如,假设我有以下代码:
#define CONCATENATE(X, Y) X ## Y
#define STRING_1 First
#define STRING_2 Second
#define STRING_3 CONCATENATE(STRING_1, STRING_2)
Run Code Online (Sandbox Code Playgroud)
有没有办法确保STRING_3将在FirstSecond以后的程序中扩展?
我正在我的容器类中实现一个方法,从数组中删除/删除一个值.例如:
// | 532 | 422 | 134 | 762 |
// | 0 | 1 | 2 | 3 |
MyObject.Remove(1); // Or MyObject.Delete(1);
// | 532 | 134 | 762 |
// | 0 | 1 | 2 |
Run Code Online (Sandbox Code Playgroud)
哪种词更常用于此类事物?
我正在为一个类创建一个类图,该类在其头文件中有许多与此类似的定义.
1 2 3 4 5
const std::pair<Controller<_Tp,_Val>*, _Val>& getHighestBidder(_Tp obj) const;
Run Code Online (Sandbox Code Playgroud)
我知道他们中的几个人做了什么,
2) says that this method will return a std::pair<Controller<_Tp, _Val>*, _Val>
3) gives the name of the function
4) defines the type of object this function accepts as a parameter
Run Code Online (Sandbox Code Playgroud)
但是,1和5是什么意思?
任何帮助/指针都会很棒.谢谢
std::fstream可以选择将流视为二进制,而不是文本.有什么不同?
据我所知,这一切都取决于文件在其他程序中的打开方式.如果我写入A二进制流,它将被转换为01000001(65,AASCII码) - 完全相同的表示.这可以读作文本编辑器中的字母"A",或01000001其他程序的二进制序列.
我错过了什么,或者流是否被认为是二进制没有任何区别?
我已经设置了一个简单的测试来链接D代码和C,但我遇到了链接器问题.
// Compiled with "gcc -c CTest.c."
void SayHello()
{
printf("%s", "Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
// Compiled with "dmd DTest.d CTest.o."
extern (C) void SayHello();
void main()
{
SayHello();
}
Run Code Online (Sandbox Code Playgroud)
ld 吐出:
ld: warning: in CTest.o, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols:
"_SayHello", referenced from:
__Dmain in DTest.o
ld: symbol(s) not found
Run Code Online (Sandbox Code Playgroud)
我已经尝试手动指定CTest.c的架构-m32 -march=i386,但这在运行时给了我一个总线错误.我以前从来没有遇到过公共汽车错误,所以这就是我的头脑.
我做错了什么?
std.process有一个很好的shell()功能.
import std.process;
import std.stdio;
void main()
{
string Output = shell("ls .");
writeln("The contents of this directory are:");
write(Output);
}
Run Code Online (Sandbox Code Playgroud)
它在Phobos源中有记录,但不在线.这让我在实际代码中使用它有点犹豫.它是实验性的还是不稳定的,还是在线文档落后?
如果模板成员是模板的唯一成员,并且它们共享模板的名称,则可以隐式引用模板成员:
template foo(int number)
{
immutable int foo = number;
}
void main()
{
writeln(foo!(123)); // Okay.
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我想明确地引用该成员呢?
writeln(foo!(123).foo); // Error: attempts to access the foo property of int.
Run Code Online (Sandbox Code Playgroud)
我没有充分的理由,但我觉得这一定是可能的.
在单独的文件中使用函数实现的正确语法是什么?例如:
foo.h中
int Multiply(const int Number);
Run Code Online (Sandbox Code Playgroud)
Foo.cpp中
#include "foo.h"
int Multiply(const int Number)
{
return Number * 2;
}
Run Code Online (Sandbox Code Playgroud)
我看到这用了很多,但是当我尝试它时,我得到一个与缺少main()函数有关的错误.即使我尝试编译工作代码,我也会收到错误.
我做了以下运算符重载测试:
#include <iostream>
#include <string>
using namespace std;
class TestClass
{
string ClassName;
public:
TestClass(string Name)
{
ClassName = Name;
cout << ClassName << " constructed." << endl;
}
~TestClass()
{
cout << ClassName << " destructed." << endl;
}
void operator=(TestClass Other)
{
cout << ClassName << " in operator=" << endl;
cout << "The address of the other class is " << &Other << "." << endl;
}
};
int main()
{
TestClass FirstInstance("FirstInstance");
TestClass SecondInstance("SecondInstance");
FirstInstance = …Run Code Online (Sandbox Code Playgroud) c++ class operator-overloading operators assignment-operator