Ive got a little question to my Syntax. I made this Struct
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;
So, this is in my .h File. Now I want into my .cpp File that Start
is a new Node
It should be something this way Start = new Node;
Can you tell me the Syntax to do that?
Thanks
Since your variable is const, you could not modify it's content. I guess you'd like to have an ability to modify them but still keep pointer (Start) as const. The next code will do it.
// .h file
...
extern Node* const Start;
// .cpp file
Node* const Start = new Node();
int main()
{
Start->name = "user2675121";
delete Start;
return 0;
}
Keyword 'extern' used with 'Start' (int .h file) tells compiler that this variable will be initialized somewhere else. And const should be placed after '*' to make a pointer (not its data) const. But using a global variables is always a bad decision.
I presume you are trying to do the following in your cpp file. start = new Node();
in that case why 'const node* start'. Making const, will not allow new data to be written on that variable.
My suggestion is removed '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;
}
In this, at start->info says "Node::info readonly"..ie you can't assign structure data on start
. So kindly remove const and do necessary operations
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.