c++ does not name a type

前端 未结 2 868
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 19:42

So I\'m having some type problems in my c++ program. Here is the code:

#include \"NHSFileparser.h\"
#include \"NHSFileController.h\"
#include 
#inc         


        
2条回答
  •  情歌与酒
    2021-01-28 20:28

    directories.push_back(directory1);
    

    Code statements like that can only go inside functions.

    In C++11, you can initialise the vector in its declaration:

    std::vector directories {"...", "..."};
    

    If you're stuck in the past, then you could move the push_back statements inside main, or use something like the Boost.Assignment library, or write a function to return a populated vector:

    std::vector make_directories() {
        std::vector directories;
        directories.push_back("...");
        directories.push_back("...");
        return directories;
    }
    
    std::vector directories = make_directories();
    

提交回复
热议问题