小编ton*_*oni的帖子

ISO C++禁止在没有类型的情况下声明'vector'

当我编译我的项目时,我得到了tools.h/tools.h的奇怪错误.字符串和向量类通过std命名空间使用.我只是看不出任何错误.

g++ powerpi.cpp structs.cpp xmlreader.cpp tools.cpp -o powerpi
In file included from structs.cpp:5:
tools.h:5: error: ISO C++ forbids declaration of ‘vector’ with no type
tools.h:5: error: invalid use of ‘::’
tools.h:5: error: expected ‘;’ before ‘<’ token
Run Code Online (Sandbox Code Playgroud)

的Tools.h

class Tools {
  public:
    template<typename T>
    static std::string convert(T);
    static std::vector<std::string> explode(std::string, std::string);
};
Run Code Online (Sandbox Code Playgroud)

tools.cpp

#include <sstream>
#include <vector>
#include <string>

#include "tools.h"

template <typename T>
std::string Tools::convert(T Number)
{ 
  std::ostringstream ss;
  ss << Number;
  return ss.str();
}

std::vector<std::string> Tools::explode(std::string delimiter, std::string …
Run Code Online (Sandbox Code Playgroud)

c++ g++

1
推荐指数
1
解决办法
9497
查看次数

标签 统计

c++ ×1

g++ ×1