小编Max*_*xpm的帖子

如何在预处理后查看文件的外观?

如何查看预处理的结果?例如,假设我有以下代码:

#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以后的程序中扩展?

c++ debugging c-preprocessor

3
推荐指数
1
解决办法
2460
查看次数

"删除"与"删除"

我正在我的容器类中实现一个方法,从数组中删除/删除一个值.例如:

// | 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)

哪种词更常用于此类事物?

c++ arrays

3
推荐指数
1
解决办法
412
查看次数

这个C++声明是什么意思?

我正在为一个类创建一个类图,该类在其头文件中有许多与此类似的定义.

  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是什么意思?

任何帮助/指针都会很棒.谢谢

c++

3
推荐指数
1
解决办法
208
查看次数

什么使二进制流特殊?

std::fstream可以选择将流视为二进制,而不是文本.有什么不同?

据我所知,这一切都取决于文件在其他程序中的打开方式.如果我写入A二进制流,它将被转换为01000001(65,AASCII码) - 完全相同的表示.这可以读作文本编辑器中的字母"A",或01000001其他程序的二进制序列.

我错过了什么,或者流是否被认为是二进制没有任何区别?

c++ binary text fstream file

3
推荐指数
1
解决办法
945
查看次数

这个D-to-C连接有什么问题?

我已经设置了一个简单的测试来链接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,但这在运行时给了我一个总线错误.我以前从来没有遇到过公共汽车错误,所以这就是我的头脑.

我做错了什么?

c linker d

3
推荐指数
1
解决办法
256
查看次数

我可以依赖shell()的存在吗?

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源中有记录,但不在线.这让我在实际代码中使用它有点犹豫.它是实验性的还是不稳定的,还是在线文档落后?

documentation d standard-library phobos

3
推荐指数
1
解决办法
94
查看次数

为什么opAssign不能为类重载?

该表说,赋值重载只适用于结构,而不是类.这让我感到惊讶.不是A = B无害的语法糖吗?将其限制为结构的设计理由是什么?

d operator-overloading design-rationale assignment-operator

3
推荐指数
1
解决办法
327
查看次数

如何明确引用此模板成员?

如果模板成员模板的唯一成员,并且它们共享模板的名称,可以隐式引用模板成员:

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)

我没有充分的理由,但我觉得这一定是可能的.

templates d explicit implicit

3
推荐指数
1
解决办法
90
查看次数

单独文件中的函数实现

在单独的文件中使用函数实现的正确语法是什么?例如:

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()函数有关的错误.即使我尝试编译工作代码,我也会收到错误.

c++ implementation header function

2
推荐指数
1
解决办法
1万
查看次数

类分配运算符

我做了以下运算符重载测试:

#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

2
推荐指数
2
解决办法
9925
查看次数