C++ 没有参数列表的模板名称使用无效
我试图做两件让我产生问题的事情: 1) typedef anC++ 没有参数列表的模板名称使用无效,c++,templates,C++,Templates,我试图做两件让我产生问题的事情: 1) typedef anstd::vector 2) 声明一个std::auto_ptr 这两个都给了我一个错误“在没有参数列表的情况下,模板名'std::vector/auto_ptr'的使用无效”。以下是导致错误的标题: ResourceLocationDefinition.h // ResourceLocationDefinition contains the information needed // by Ogre to load an extern
std::vector
2) 声明一个
std::auto_ptr
这两个都给了我一个错误“在没有参数列表的情况下,模板名'std::vector/auto_ptr'的使用无效”
。以下是导致错误的标题:
ResourceLocationDefinition.h
// ResourceLocationDefinition contains the information needed
// by Ogre to load an external resource.
#ifndef RESOURCELOCATIONDEFINITION_H_
#define RESOURCELOCATIONDEFINITION_H_
#include "string"
#include "vector"
struct ResourceLocationDefinition
{
ResourceLocationDefinition(std::string type, std::string location, std::string section) :
type(type),
location(location),
section(section)
{
}
~ResourceLocationDefinition() {}
std::string type;
std::string location;
std::string section;
};
typedef std::vector ResourceLocationDefinitionVector;
#endif
#ifndef ENGINEMANAGER_H_
#define ENGINEMANAGER_H_
#include "memory"
#include "string"
#include "map"
#include "OGRE/Ogre.h"
#include "OIS/OIS.h"
#include "ResourceLocationDefinition.h"
// define this to make life a little easier
#define ENGINEMANAGER OgreEngineManager::Instance()
// All OGRE objects are in the Ogre namespace.
using namespace Ogre;
// Manages the OGRE engine.
class OgreEngineManager :
public WindowEventListener,
public FrameListener
{
public:
// Bunch of unrelated stuff to the problem
protected:
// Constructor. Initialises variables.
OgreEngineManager();
// Load resources from config file.
void SetupResources();
// Display config dialog box to prompt for graphics options.
bool Configure();
// Setup input devices.
void SetupInputDevices();
// OGRE Root
std::auto_ptr root;
// Default OGRE Camera
Camera* genericCamera;
// OGRE RenderWIndow
RenderWindow* window;
// Flag indicating if the rendering loop is still running
bool engineManagerRunning;
// Resource locations
ResourceLocationDefinitionVector resourceLocationDefinitionVector;
// OIS Input devices
OIS::InputManager* mInputManager;
OIS::Mouse* mMouse;
OIS::Keyboard* mKeyboard;
};
#endif /* ENGINEMANAGER_H_ */
EngineManager.h
// ResourceLocationDefinition contains the information needed
// by Ogre to load an external resource.
#ifndef RESOURCELOCATIONDEFINITION_H_
#define RESOURCELOCATIONDEFINITION_H_
#include "string"
#include "vector"
struct ResourceLocationDefinition
{
ResourceLocationDefinition(std::string type, std::string location, std::string section) :
type(type),
location(location),
section(section)
{
}
~ResourceLocationDefinition() {}
std::string type;
std::string location;
std::string section;
};
typedef std::vector ResourceLocationDefinitionVector;
#endif
#ifndef ENGINEMANAGER_H_
#define ENGINEMANAGER_H_
#include "memory"
#include "string"
#include "map"
#include "OGRE/Ogre.h"
#include "OIS/OIS.h"
#include "ResourceLocationDefinition.h"
// define this to make life a little easier
#define ENGINEMANAGER OgreEngineManager::Instance()
// All OGRE objects are in the Ogre namespace.
using namespace Ogre;
// Manages the OGRE engine.
class OgreEngineManager :
public WindowEventListener,
public FrameListener
{
public:
// Bunch of unrelated stuff to the problem
protected:
// Constructor. Initialises variables.
OgreEngineManager();
// Load resources from config file.
void SetupResources();
// Display config dialog box to prompt for graphics options.
bool Configure();
// Setup input devices.
void SetupInputDevices();
// OGRE Root
std::auto_ptr root;
// Default OGRE Camera
Camera* genericCamera;
// OGRE RenderWIndow
RenderWindow* window;
// Flag indicating if the rendering loop is still running
bool engineManagerRunning;
// Resource locations
ResourceLocationDefinitionVector resourceLocationDefinitionVector;
// OIS Input devices
OIS::InputManager* mInputManager;
OIS::Mouse* mMouse;
OIS::Keyboard* mKeyboard;
};
#endif /* ENGINEMANAGER_H_ */
错误很明显
auto_ptr
和vector
是模板。它们要求您指定实际要与它们一起使用的类型
struct my_type {
int x, y;
};
std::vector<my_type> v; // a vector of my_type
std::vector<int> iv; // a vector of integers
struct my\u类型{
int x,y;
};
std::向量v;//我的_类型的向量
标准::向量iv;//整数向量
关于
auto\u ptr
:由于其奇怪的语义,它已被弃用。考虑使用<代码> STD::UnQuyJPTR <代码>(在您的平台上可用)或<代码> Boo::SCONDEXYPTR (当您有一个Boost依赖关系)时, < P>当使用模板时,您必须提供模板参数,对于您的向量,您可能想做这样的事情:
typedef std::vector<ResourceLocationDefinition> ResourceLocationDefinitionVector;
std::auto_ptr<Root> root;
<>我相信你想要一个<代码> OGRE::root <代码>指针,对吧?< /P>为什么不给I塔模板参数?在这样做之后,我得到了一大堆新的错误:我在路上看电影,所以我将稍后再仔细看看。如果不是很明显,请不要浪费不必要的时间。我不想让别人为我工作;)它们基本上都是未定义的引用。不确定为什么给出模板参数会导致这种情况发生。似乎您可能没有与ogre链接,您的项目中是否包含ogre库?代码块已将它们链接到“我的项目构建选项”下。我以前也没有这些问题。我只是在终端中手动构建了它,它工作得很好,不知道为什么代码块会忽略它们。感谢您的帮助Nick.GCC支持C++11。我到家后会看文档的,谢谢你的提示。