int main()
{
int *d=0;
printf("%d\n",*d);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.
>cc legal.c
> ./a.out
0
Run Code Online (Sandbox Code Playgroud)
如果我更改语句int *d=0;,int *d=1;
我会看到错误.
cc: "legal.c", line 6: error 1522: Cannot initialize a pointer with an integer constant other than zero.
Run Code Online (Sandbox Code Playgroud)
很明显,它只允许零.我想知道当我们这样做时,内存中发生了什么,这int *d=0使得它成为有效的语法.
我只是出于好奇而问这个!
我有一些 Motif 代码,也使用 Xmt 小部件集中的小部件。
它包括“Xm/XmStrDefs.h”和“Xmt/ComboBox.h”。
但是,这两个文件中都定义了一些宏:
// XmStrDefs.h:
#define XmNarrowSize "arrowSize"
// ComboBox.h:
#define XmNarrowSize "arrowSize"
Run Code Online (Sandbox Code Playgroud)
这些是我不允许更改的系统头文件。我听说 gcc 能够忽略系统标头中的警告。
我如何告诉 gcc 这些标头是系统标头?
或者,如何告诉 gcc 忽略重新定义错误?
基本上,如何在不更改这些标头的情况下抑制此警告?
class a
{
protected:
const int _ID;
public:
a::a(int id){};
a::top(int num);
};
class b : public a
{
static int ok;
b::b(int id):a(id){};
a::top(ok);
}
int main()
{
int t=5;
b opj=b(t);
}
Run Code Online (Sandbox Code Playgroud)
首先,为什么我得到这个编译错误,只有当我删除const时解决
非静态const成员'const int Student :: _ ID',不能使用默认赋值运算符 - 实例化自'void std :: vector :: _ M_insert_aux(__ gnu_cxx :: __ normal_iterator,const _Tp&)[with _Tp = Student,_Alloc =的std ::分配器]"
第二
我有另一个问题
未定义的引用b :: ok
我试图声明一个字节数组,所以我可以通过它们并分别使用它们中的每一个.这是阵列
const BYTE keybyte[] = {
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 0x58,
0x59, 0x5A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x25, 0x27, 0x26, 0x28,
0x0D, 0x20, 0x10, 0x11, 0x12, 0x18};
Run Code Online (Sandbox Code Playgroud)
由于某种原因,当我编译它给我这些错误:/
error C2143: syntax error : missing '}' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2143: syntax …Run Code Online (Sandbox Code Playgroud) 这是我的实现文件:
using namespace std;
#include <iostream>
#include <iomanip>
#include <string>
#include <stack> //line 5
#include "proj05.canvas.h"
//----------------Constructor----------------//
Canvas::Canvas() //line 10
{
Title = "";
Nrow = 0;
Ncol = 0;
image[][100]; // line 15
position.r = 0;
position.c = 0;
}
//-------------------Paint------------------// line 20
void Canvas::Paint(int R, int C, char Color)
{
cout << "Paint to be implemented" << endl;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这些:
proj05.canvas.cpp: In function 'std::istream& operator>>(std::istream&,
Canvas&)':
proj05.canvas.cpp:11: error: expected `;' before '{' token
proj05.canvas.cpp:22: error: a function-definition is …Run Code Online (Sandbox Code Playgroud) 使用这样的伪代码:
class FooBar {
public:
int property;
static int m_static;
}
FooBar instance1 = new FooBar();
FooBar instance2 = new FooBar();
Run Code Online (Sandbox Code Playgroud)
如果我设置instance1的属性,它显然不会影响第二个.但是,如果我改为设置静态属性,则更改应传播到类的每个实例.
如果instance1和2在不同的线程中,这也会发生吗?
我无法理解为什么会这样:
#include <iostream>
using namespace std;
int main(){
signed long int count = 1;
//...
count++;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而,如果我将标识符声明(限制)移动到脚本的开头(就在使用命名空间之后),则无法编译错误"count unclared(首次在此函数中使用)" - 突出显示行'count ++; ".
或者,Codepad导致以下错误:
In function 'int main()':
Line 16: error: reference to 'count' is ambiguous
compilation terminated due to -Wfatal-errors.
Run Code Online (Sandbox Code Playgroud)
谢谢,
将.
所以该程序应该做什么:通过键入restrict来限制应用程序在mac上打开.它应该允许通过使用与以前相同的名称再次键入restrict来访问应用程序.
该程序正在做什么:限制应用程序工作正常.但是当我再次输入restrict时,会出现以下输出:
CandyBar
\277_\377CandyBar
\277_\377Restricting application
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
chown: /Applications/CandyBar
\277_\377.app: No such file or directory
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它会\277_\377在字符串末尾添加字符.这是我的源代码:
for (int i = 0; strlen(argument) + 14 >= i; i++) {
argument[i] = '\0';
}
cout << argument;
getArguments();
argument[strlen(argument) - 1] = '\0';
cout << argument;
string application(argument);
cout << application;
if (!restrictedApplication[application]) {
restrictedApplication[application] = false;
}
if (restrictedApplication[application] == false) {
cout << …Run Code Online (Sandbox Code Playgroud) 我有一个名为extBlock的类.
然后我用这个做一个类的实例
extBlock mainBlock = new extBlock(1, 1024);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:错误C2440:'初始化':无法从'extBlock*'转换为'extBlock'
任何人都可以帮助我解决为什么我收到此错误.
我在网上看过用指针声明它的例子
extBlock *mainBlock = new extBlock(1, 1024);
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做,它不会让我调用mainBlock的功能
我有一个小代码,它在堆上分配一些内存,然后在它使用后尝试释放它.我在内存映射中遇到此错误.
守则是::
void merge(int *arr, int start, int mid, int end)
{
int i = 0, j = 0, k = 0, tmp1 = 0, siz = 0;
int *pt = NULL;
j = start, k = mid+1, tmp1 = start;
siz = (end - start) + 1;
if ((pt = malloc(siz * sizeof(int))) == NULL) /* line 32 */
{
printf("\n ERROR Aloocating mem \n");
return;
}
while (j <= mid && k <= end)
{
if (arr[j] <= …Run Code Online (Sandbox Code Playgroud)