[英]Function parameter “not declared in this scope”. Parameter is visible in h file
[英]Function parameter 'was not declared in this scope' in the header file
我在一个头文件(C ++)中声明一个函数时遇到问题,这是文件的外观:
#ifndef MACTRANSFERINCLUDE
#define MACTRANSFERINCLUDE
#ifdef USE_MAC
#include <string>
#include <boost/shared_ptr.hpp>
using namespace std;
boost::shared_ptr<wstring> browseFolder();
boost::shared_ptr<vector<wstring>> getFilesInDirRecursiveImplementation(boost::shared_ptr<vector<wstring>> dirs, boost::shared_ptr<vector<wstring>> files);
#endif
#endif
生成项目时(对于XCode中的Mac OSX),我得到“在此范围内未声明'dirs'”。
如果我也声明一个函数
boost::shared_ptr<vector<wstring>> foo();
我收到错误“函数调用不能出现在常量表达式中”。 我对C ++不太熟悉,因此不胜感激。
您需要包含标题<vector>
#include <vector>
也许这是错误的原因。
我认为声明之间没有太大的区别
boost::shared_ptr<wstring> browseFolder();
和
boost::shared_ptr<vector<wstring>> foo();
所以编译器应该发出错误
“函数调用不能出现在常量表达式中”。
也用于第一个声明。
唯一的区别是第二个声明使用了未声明的vector
。 至少看不到标头中声明它的位置。
使用指令也是一个坏主意
using namespace std;
我将其删除并写
boost::shared_ptr<std::wstring> browseFolder();
boost::shared_ptr<std::vector<std::wstring>> getFilesInDirRecursiveImplementation(boost::shared_ptr<std::vector<std::wstring>> dirs, boost::shared_ptr<std::vector<std::wstring>> files);
另一个原因是您可能需要在符号之间插入空格>>
例如
boost::shared_ptr<std::vector<std::wstring> > dirs
看起来确实确实有一个旧的编译器,它没有在模板参数声明中为符号对>>
使用新语法。 因此,您必须在这两个符号之间插入空格> >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.