4

我正在尝试做两件事给我带来问题:

1) typedef an std::vector
2) 声明一个std::auto_ptr

这两个都给了我错误"invalid use of template-name 'std::vector/auto_ptr' without an argument list"。这是导致错误的标题:

资源位置定义.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

引擎管理器.h

#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_ */
4

2 回答 2

6

使用模板时,您必须为您的向量提供模板参数,您可能想要执行以下操作:

typedef std::vector<ResourceLocationDefinition> ResourceLocationDefinitionVector;

这意味着您的向量引用ResourceLocationDefinition对象实例。

对于你这样的auto_ptr东西:

std::auto_ptr<Root> root;

我相信你想要一个Ogre::Root指针,对吗?

于 2012-11-23T22:30:12.257 回答
0

错误很明显。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

关注auto_ptr:由于其奇怪的语义,它已被弃用。考虑使用std::unique_ptr(当在您的平台上可用时)或boost::scoped_ptr(当您有 boost 依赖项时。)

于 2012-11-23T22:30:04.283 回答