没有参数列表的模板名称使用无效

Invalid use of template name without argument list

本文关键字:无效 参数 列表      更新时间:2023-10-16

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

1) 键入定义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_ */

使用模板时,您必须提供模板参数,对于您的向量,您可能希望执行以下操作:

typedef std::vector<ResourceLocationDefinition> ResourceLocationDefinitionVector;

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

对于您的auto_ptr,请像这样:

std::auto_ptr<Root> root;

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

错误很明显。 auto_ptrvector是模板。它们要求您指定实际要与它们一起使用的类型。

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(当您有提升依赖项时)。