我收到了一个编译错误:
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)
我该如何解决这个问题?
在这里,我尝试了一个程序,其中局部变量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) 我试图定义ll为long 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) 我有这个
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++代码:
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)