繁体   English   中英

MFC语法将Node设置为新节点

[英]MFC Syntax set Node as new Node

我对我的语法有一个小疑问。 我做了这个结构

struct Node
{
    CString name;
    CString vorname;
    CString geburtsdatum;
    CString adresse;
    CString plz;
    CString ort;
    CString email;
    CString geschlecht;
    CString land;
    CString firma;
    CString telefon;
    CString fax;
    Node* next;
    Node* previous;
};
Node *Actual;
const Node *Start;

因此,这是在我的.h文件中。 现在我要到我的.cpp文件Start是一个new Node它应该是这样Start = new Node;

你能告诉我这样做的语法吗?

谢谢

由于您的变量是const,因此无法修改其内容。 我想您希望能够修改它们,但仍将指针(开始)保持为const。 下一个代码将执行此操作。

// .h file
...
extern Node* const Start;

// .cpp file
Node* const Start = new Node();
int main()
{
    Start->name = "user2675121";
    delete Start;
    return 0;
}

与“开始”(int .h文件)一起使用的关键字“外部”告诉编译器此变量将在其他地方初始化。 并且const应该放在'*'之后,以使指针(而不是其数据)成为const。 但是使用全局变量始终是一个错误的决定。

我认为您正在尝试在cpp文件中执行以下操作。 开始=新Node();

在那种情况下,为什么“ const node * start”。 设为const,将不允许将新数据写入该变量。

我的建议已删除“ const”

#include <stdio.h>
struct Node
{
    int info;
    Node* next;
    Node* previous;
};
int main()
{
    const Node* start ;
    int d = 4;
    start = new Node();
    start->info = d;
    printf("%d\t", start->info);

    return 0;
}

在这种情况下,在start-> info处显示“ Node :: info只读” ..ie,即无法在start上分配结构数据。 因此,请删除const并进行必要的操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM