How to fix error ininitialize vector of struct












2















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











share|improve this question




















  • 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
















2















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











share|improve this question




















  • 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














2












2








2








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











share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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














  • 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








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












1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    3














    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.






    share|improve this answer






























      3














      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.






      share|improve this answer




























        3












        3








        3







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 5:46

























        answered Jan 1 at 5:39









        taskinoortaskinoor

        39.9k7101129




        39.9k7101129
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith