How to fix error ininitialize vector of struct
This is my code. (C++98)
struct node
{
string name;
string help;
string action;
string pName;
string pHelp;
};
vector<node> commands {
node{"name1", "help1", "", "", ""},
node{"name2", "help2", "action2", "pname", "phelp"}
};
The error is
function definition does not declare parameters
c++ vector c++98
add a comment |
This is my code. (C++98)
struct node
{
string name;
string help;
string action;
string pName;
string pHelp;
};
vector<node> commands {
node{"name1", "help1", "", "", ""},
node{"name2", "help2", "action2", "pname", "phelp"}
};
The error is
function definition does not declare parameters
c++ vector c++98
1
You have to write anode
constructor for with 5 parameters. Also your code is not C++98.
– S.M.
Jan 1 at 5:36
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21
add a comment |
This is my code. (C++98)
struct node
{
string name;
string help;
string action;
string pName;
string pHelp;
};
vector<node> commands {
node{"name1", "help1", "", "", ""},
node{"name2", "help2", "action2", "pname", "phelp"}
};
The error is
function definition does not declare parameters
c++ vector c++98
This is my code. (C++98)
struct node
{
string name;
string help;
string action;
string pName;
string pHelp;
};
vector<node> commands {
node{"name1", "help1", "", "", ""},
node{"name2", "help2", "action2", "pname", "phelp"}
};
The error is
function definition does not declare parameters
c++ vector c++98
c++ vector c++98
edited Jan 1 at 5:39
user10605163
2,868624
2,868624
asked Jan 1 at 5:32
F.MF.M
1021315
1021315
1
You have to write anode
constructor for with 5 parameters. Also your code is not C++98.
– S.M.
Jan 1 at 5:36
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21
add a comment |
1
You have to write anode
constructor for with 5 parameters. Also your code is not C++98.
– S.M.
Jan 1 at 5:36
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21
1
1
You have to write a
node
constructor for with 5 parameters. Also your code is not C++98.– S.M.
Jan 1 at 5:36
You have to write a
node
constructor for with 5 parameters. Also your code is not C++98.– S.M.
Jan 1 at 5:36
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21
add a comment |
1 Answer
1
active
oldest
votes
You are probably using an old compiler but following new tutorial or book. gcc 5.4.0 gives this:
test.cpp:12:27: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
vector <node> commands {
^
test.cpp:13:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:13:46: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:14:6: error: in C++98 ‘commands’ must be initialized by constructor, not by ‘{...}’
};
Which clearly says that you either have to use c++11 at least or need to provide a constructor for node
that takes five parameters and use the old style to construct objects.
Unless you have very specific reasons to stick to c++98, I would say that moving to C++11 is the best option. Otherwise please follow books or tutorials that teach C++98 or at least describe how things were different in C++98 to avoid such problems.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993212%2fhow-to-fix-error-ininitialize-vector-of-struct%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are probably using an old compiler but following new tutorial or book. gcc 5.4.0 gives this:
test.cpp:12:27: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
vector <node> commands {
^
test.cpp:13:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:13:46: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:14:6: error: in C++98 ‘commands’ must be initialized by constructor, not by ‘{...}’
};
Which clearly says that you either have to use c++11 at least or need to provide a constructor for node
that takes five parameters and use the old style to construct objects.
Unless you have very specific reasons to stick to c++98, I would say that moving to C++11 is the best option. Otherwise please follow books or tutorials that teach C++98 or at least describe how things were different in C++98 to avoid such problems.
add a comment |
You are probably using an old compiler but following new tutorial or book. gcc 5.4.0 gives this:
test.cpp:12:27: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
vector <node> commands {
^
test.cpp:13:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:13:46: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:14:6: error: in C++98 ‘commands’ must be initialized by constructor, not by ‘{...}’
};
Which clearly says that you either have to use c++11 at least or need to provide a constructor for node
that takes five parameters and use the old style to construct objects.
Unless you have very specific reasons to stick to c++98, I would say that moving to C++11 is the best option. Otherwise please follow books or tutorials that teach C++98 or at least describe how things were different in C++98 to avoid such problems.
add a comment |
You are probably using an old compiler but following new tutorial or book. gcc 5.4.0 gives this:
test.cpp:12:27: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
vector <node> commands {
^
test.cpp:13:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:13:46: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:14:6: error: in C++98 ‘commands’ must be initialized by constructor, not by ‘{...}’
};
Which clearly says that you either have to use c++11 at least or need to provide a constructor for node
that takes five parameters and use the old style to construct objects.
Unless you have very specific reasons to stick to c++98, I would say that moving to C++11 is the best option. Otherwise please follow books or tutorials that teach C++98 or at least describe how things were different in C++98 to avoid such problems.
You are probably using an old compiler but following new tutorial or book. gcc 5.4.0 gives this:
test.cpp:12:27: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
vector <node> commands {
^
test.cpp:13:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:13:46: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
node{"name1","help1", "", "" , ""}, node{"name2", "help2","action2", "pname", "phelp"}
^
test.cpp:14:6: error: in C++98 ‘commands’ must be initialized by constructor, not by ‘{...}’
};
Which clearly says that you either have to use c++11 at least or need to provide a constructor for node
that takes five parameters and use the old style to construct objects.
Unless you have very specific reasons to stick to c++98, I would say that moving to C++11 is the best option. Otherwise please follow books or tutorials that teach C++98 or at least describe how things were different in C++98 to avoid such problems.
edited Jan 1 at 5:46
answered Jan 1 at 5:39


taskinoortaskinoor
39.9k7101129
39.9k7101129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993212%2fhow-to-fix-error-ininitialize-vector-of-struct%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You have to write a
node
constructor for with 5 parameters. Also your code is not C++98.– S.M.
Jan 1 at 5:36
@S.M Thank you. I'm new in c++. Is this code wrong?
– F.M
Jan 1 at 5:39
It's wrong C++98. The constructs you use in C++ now often depend on dialect
– StoryTeller
Jan 1 at 6:21