小编Rak*_*111的帖子

自动指针= NULL错误

我收到了一个编译错误:

error: unable to deduce ‘auto*’ from ‘0l’
Run Code Online (Sandbox Code Playgroud)

在尝试编译我的代码时:

random_device rd;
minstd_rand gen0(rd());
knuth_b gen1(rd());
ranlux24_base gen2(rd());

auto * generator = NULL; // error

switch(generatortmp) {
    case 0: generator = &gen0;
    more cases...
}
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

c++ pointers auto c++11

-1
推荐指数
1
解决办法
395
查看次数

分配给静态变量的局部变量;'c'中的编译错误,但在c ++中成功

在这里,我尝试了一个程序,其中局部变量x被分配给静态变量i并检查它是否分配值.

在'C'中编程:显然它会产生编译时错误(初始化元素不是常量).

然后我在C++中实现了相同的程序:这次我没有得到编译时错误,但输出为"相等"(不应该像以前一样给出编译时错误).

请解释一下.

int main() //C code
{
    int x=10;
    static int i=x;
    if(i==x)
        printf("Equal");
    return 1;
}


int main() //C++ code
{
    int x=10;
    static int i=x;
    if(i==x)
        cout<<"equal";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c c++

-1
推荐指数
1
解决办法
78
查看次数

#define 的“声明未声明任何内容”错误

我试图定义lllong long. 但是,这没有编译并引发错误。

我在 Windows 机器上使用 VS Code。我也在使用 gcc 8.2.0 版。

这是代码 -

#include <bits/stdc++.h>

using namespace std;

#define ll long long int;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t;

    cin >> t;

    return 0;
}

Run Code Online (Sandbox Code Playgroud)

在编译这个时,我收到了这个错误 -

test.cpp: In function 'int main()':
test.cpp:5:22: error: declaration does not declare anything [-fpermissive]
 #define ll long long int;
                      ^~~
test.cpp:12:5: note: in expansion of macro 'll'
     ll t;
     ^~
test.cpp:12:8: error: 't' was not declared in this scope …
Run Code Online (Sandbox Code Playgroud)

c++ macros compiler-errors g++ c++14

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

如果一个类的大小只有一个char 8,如果它实际上是继承的那么?

我有这个

class Empty {};  // Empty class

class Derived : virtual public Empty
{
        char c;
};
Run Code Online (Sandbox Code Playgroud)

在我的机器上,sizeof(Derived);8,为什么?不是1因为它只有1 char吗?

当我删除虚拟继承时,sizeof(Derived);1.

c++

-4
推荐指数
1
解决办法
49
查看次数

C# - ref this(引用自己)

假设我有一个C++代码:

class A {
    int x = 20;

    void Interact(A* Other) {
        if (x % 2 == 0) { Other->x++; x /= 2; } //some advanced operation
    }
public:
    void MakeInteraction(A* Other) {
        Interact(Other);
        Other->Interact(this);
    }
};

int main() {
    A a, b;
    a.MakeInteraction(&b);
}
Run Code Online (Sandbox Code Playgroud)

问题是,如果我想在C#中做类似的东西,我遇到了障碍 - 当然我不需要使用指针,但我不能使用this对象的引用:

class A
{
    int x = 20;
    void Interact(ref A Other)
    {
        if (x % 2 == 0) { Other.x++; x /= 2; }
    }
    public void MakeInteraction(ref A Other) …
Run Code Online (Sandbox Code Playgroud)

c# reference this

-8
推荐指数
1
解决办法
859
查看次数

标签 统计

c++ ×4

auto ×1

c ×1

c# ×1

c++11 ×1

c++14 ×1

compiler-errors ×1

g++ ×1

macros ×1

pointers ×1

reference ×1

this ×1