Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;映射模板参数无效_C++_Templates_Dictionary_Stdmap_Invalid Argument - Fatal编程技术网

C++ C++;映射模板参数无效

C++ C++;映射模板参数无效,c++,templates,dictionary,stdmap,invalid-argument,C++,Templates,Dictionary,Stdmap,Invalid Argument,我试图创建一个映射,其值是我在另一个文件中定义的类;即,FoodItemLookup。但是,C++给了我错误: 模板参数1无效 我觉得这很奇怪,因为我没有使用任何模板 如果有人能向我解释我做错了什么,我将不胜感激。我不认为我可以发布所有的代码,但下面是有问题的代码片段: 制作地图的尝试: std::map<string, FoodItemLookup> foodCatalogue; std::map foodCatalogue; FoodItemLookup.h文件的简要概述:

我试图创建一个映射,其值是我在另一个文件中定义的类;即,
FoodItemLookup
。但是,C++给了我错误:

模板参数1无效

我觉得这很奇怪,因为我没有使用任何模板

如果有人能向我解释我做错了什么,我将不胜感激。我不认为我可以发布所有的代码,但下面是有问题的代码片段:

制作地图的尝试:

std::map<string, FoodItemLookup> foodCatalogue;
std::map foodCatalogue;
FoodItemLookup.h文件的简要概述:

#ifndef FOODITEMLOOKUP
#define FOODITEMLOOKUP

#include <string>

class FoodItemLookup
{
  private:
  ...

  public:

  //constructor
  FoodItemLookup(std::string upc, int shelfLife, std::string name);

  //copy constructor
  FoodItemLookup(const FoodItemLookup &other);

  //destructor
  ~FoodItemLookup();

  ...
);

#endif
#ifndef FOODITEMLOOKUP
#定义FOODITEMLOOKUP
#包括
FoodItemLookup类
{
私人:
...
公众:
//建造师
FoodItemLookup(std::string upc,int shelfLife,std::string name);
//复制构造函数
FoodItemLookup(const FoodItemLookup&其他);
//析构函数
~FoodItemLookup();
...
);
#恩迪夫

在第一个模板参数中的
字符串的from中应该有
std:

std::map<std::string, FoodItemLookup> foodCatalogue;
std::map foodCatalogue;

“我觉得这很奇怪,因为我没有使用任何模板。”

实际上
std::map
使用模板。这就是为什么在实例化
std::map
时,需要在
之间传递两种类型(这里是
std::string
FoodItemLookup


确切的错误消息是什么?你没有发布足够的代码让任何人来帮助你。有太多的事情我们必须猜测,但我们无法得出任何结论。如果你在声明地图之前不做任何特殊的事情,你将不得不在那里使用
std::string
,就像在类声明中一样。哦…哇!我想了些什么我的课不好,总是小问题,谢谢。