c++ does not name a type

前端 未结 2 869
佛祖请我去吃肉
佛祖请我去吃肉 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:27

    You cannot put statements outside functions, only declarations and definitions. Put your code inside main.

    0 讨论(0)
  • 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<std::string> 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<std::string> make_directories() {
        std::vector<std::string> directories;
        directories.push_back("...");
        directories.push_back("...");
        return directories;
    }
    
    std::vector<std::string> directories = make_directories();
    
    0 讨论(0)
提交回复
热议问题