[关闭]之前缺少模板参数

Posted

技术标签:

【中文标题】[关闭]之前缺少模板参数【英文标题】:missing template arguments before [closed] 【发布时间】:2016-03-29 02:07:13 【问题描述】:

我在强制我的代码时遇到问题。错误消息指示 Map.h 中的“缺少模板参数”。但我确实相信 Map.h 中没有任何错误,因为它来自 Minisat,它是一个复杂的 API。所以我认为这是我在代码或makefile中的错。我试过很多次了,你能帮我吗?非常感谢!

The error message is:
Compiling: queryOrac/queryOrac.o
In file included from /home/parallels/Desktop/Incremental_Solver/core/SolverTypes.h:30:0,
                 from /home/parallels/Desktop/Incremental_Solver/core/Solver.h:28,
                 from /home/parallels/Desktop/Incremental_Solver/simp/SimpSolver.h:25,
                 from /home/parallels/Desktop/Incremental_Solver/queryOrac/queryOrac.cc:12:
/home/parallels/Desktop/Incremental_Solver/mtl/Map.h: In member function ‘uint32_t Minisat::Hash<K>::operator()(const K&) const’:
/home/parallels/Desktop/Incremental_Solver/mtl/Map.h:32:99: error: missing template arguments before ‘(’ token
 template<class K> struct Hash   uint32_t operator()(const K& k)               const  return hash(k);   ;
                                                                                                   ^
/home/parallels/Desktop/Incremental_Solver/mtl/Map.h: In member function ‘uint32_t Minisat::DeepHash<K>::operator()(const K*) const’:
/home/parallels/Desktop/Incremental_Solver/mtl/Map.h:35:103: error: missing template arguments before ‘(’ token
 template<class K> struct DeepHash   uint32_t operator()(const K* k)               const  return hash(*k);   ;
                                                                                                       ^
make: *** [/home/parallels/Desktop/Incremental_Solver/queryOrac/queryOrac.o] Error 1

.cc 文件是(这个文件是 .h 文件的实现):

#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <regex>

#include "queryOrac/queryOrac.h"
#include "incre/tools.h"
#include "incre/dict.h"
#include "simp/SimpSolver.h"
#include "utils/System.h"
#include "utils/ParseUtils.h"
#include "utils/Options.h"
#include "core/Dimacs.h"

using namespace std;
using namespace Minisat;
using namespace Incre;

Oracle::Oracle(const char * ora, const char * PI, const char * PO)

    cout << "a Oracle is created" << endl;
    PI_path = PI;
    PO_path = PO;
    Orac_Path = ora;


void Oracle::process()

    parse_PI();
    assign_PI();
    solve();


void Oracle::parse_PI() 
    cout << "reading from " << PI_path << endl;
    ifstream infile;
    infile.open(PI_path, ios::in);
    string first_line;
    string second_line;

    getline(infile, first_line);
    getline(infile, second_line);

    vector<string> name_temp;
    vector<string> value_temp;
    SplitString(first_line, name_temp, " ");
    SplitString(second_line, value_temp, " ");

    vector<string>::iterator value = value_temp.begin();
    for(vector<string>::iterator name = name_temp.begin(); name != name_temp.end(); ++name)
    
        PI_temp.insert(pair<int, string>(varIndexDict[*name], *value));
        value++;
    


void Oracle::assign_PI()
    vector<int>::iterator position = pisIndex.begin();
    for(map<int, string>::iterator index = PI_temp.begin(); index != PI_temp.end(); ++index)
    
        if(index->second == "1") PI_assignment_cnf.push_back(tostring(*position) + " 0\n");
        else if(index->second == "0") PI_assignment_cnf.push_back("-" + tostring(*position) + " 0\n");
        position++;
    
    PI_assignment_cnf.insert(PI_assignment_cnf.begin(), "c this is assign_PI\n");
    cnFile += PI_assignment_cnf;
    print_vector(cnFile, "cnFile");



void Oracle::solve()
    cout << " start solving" << endl;


我的makefile是:

##
##  Template makefile for Standard, Profile, Debug, Release, and Release-static versions
##
##    eg: "make rs" for a statically linked release version.
##        "make d"  for a debug version (no optimizations).
##        "make"    for the standard version (optimized, but with debug information and assertions active)

PWD        = $(shell pwd)
EXEC      ?= $(notdir $(PWD))

CSRCS      = $(wildcard $(PWD)/*.cc) 
DSRCS      = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc)))
CHDRS      = $(wildcard $(PWD)/*.h)
COBJS      = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o)

PCOBJS     = $(addsuffix p,  $(COBJS))
DCOBJS     = $(addsuffix d,  $(COBJS))
RCOBJS     = $(addsuffix r,  $(COBJS))


CXX       ?= g++ 
CFLAGS    ?= -Wall -Wno-parentheses -std=c++11 
LFLAGS    ?= -Wall

COPTIMIZE ?= -O3

CFLAGS    += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS
LFLAGS    += -lz

.PHONY : s p d r rs clean 

s:  $(EXEC)
p:  $(EXEC)_profile
d:  $(EXEC)_debug
r:  $(EXEC)_release
rs: $(EXEC)_static

libs:   lib$(LIB)_standard.a
libp:   lib$(LIB)_profile.a
libd:   lib$(LIB)_debug.a
libr:   lib$(LIB)_release.a

## Compile options
%.o:            CFLAGS +=$(COPTIMIZE) -g -D DEBUG
%.op:           CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG
%.od:           CFLAGS +=-O0 -g -D DEBUG
%.or:           CFLAGS +=$(COPTIMIZE) -g -D NDEBUG

## Link options
$(EXEC):        LFLAGS += -g
$(EXEC)_profile:    LFLAGS += -g -pg
$(EXEC)_debug:      LFLAGS += -g
#$(EXEC)_release:   LFLAGS += ...
$(EXEC)_static:     LFLAGS += --static

## Dependencies
$(EXEC):        $(COBJS)
$(EXEC)_profile:    $(PCOBJS)
$(EXEC)_debug:      $(DCOBJS)
$(EXEC)_release:    $(RCOBJS)
$(EXEC)_static:     $(RCOBJS)

lib$(LIB)_standard.a:   $(filter-out */Main.o,  $(COBJS))
lib$(LIB)_profile.a:    $(filter-out */Main.op, $(PCOBJS))
lib$(LIB)_debug.a:  $(filter-out */Main.od, $(DCOBJS))
lib$(LIB)_release.a:    $(filter-out */Main.or, $(RCOBJS))


## Build rule
%.o %.op %.od %.or: %.cc
    @echo Compiling: $(subst $(MROOT)/,,$@)
    @$(CXX) $(CFLAGS) -c -o $@ $<

## Linking rules (standard/profile/debug/release)
$(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static:
    @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
    @$(CXX) $^ $(LFLAGS) -o $@

## Library rules (standard/profile/debug/release)
lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a:
    @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
    @$(AR) -rcsv $@ $^

## Library Soft Link rule:
libs libp libd libr:
    @echo "Making Soft Link: $^ -> lib$(LIB).a"
    @ln -sf $^ lib$(LIB).a

## Clean rule
clean:
    @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \
      $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk 

## Make dependencies
depend.mk: $(CSRCS) $(CHDRS)
    @echo Making dependencies
    @$(CXX) $(CFLAGS) -I$(MROOT) \
       $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk
    @for dir in $(DEPDIR); do \
          if [ -r $(MROOT)/$$dir/depend.mk ]; then \
          echo Depends on: $$dir; \
          cat $(MROOT)/$$dir/depend.mk >> depend.mk; \
          fi; \
      done

-include $(MROOT)/mtl/config.mk
-include depend.mk

【问题讨论】:

【参考方案1】:

您的问题是由于using namespace std;。不要那样做,永远

有人说只要不在头文件中就可以,但他们错了,你的错误就是一个很好的例子。

在这种情况下,您不小心引用了 std::hash,它是一个 class 模板,因此与函数模板不同,&lt;&gt; 不能省略。

【讨论】:

嗨,非常感谢,它解决了我的问题。如果有一个在多个名称空间中通用的标识符,请提出一个快速的问题。有没有优先使用,比如先“使用”先使用?比如先在std中声明hash,然后在incre中声明hash,然后在std中声明hash而不是incre的,对吗?

以上是关于[关闭]之前缺少模板参数的主要内容,如果未能解决你的问题,请参考以下文章

缺少 类模板 “deque“ 的参数列表和参数列表有两个或两个以上的形参

缺少 类模板 “deque“ 的参数列表和参数列表有两个或两个以上的形参

如何修复“UUID 类型的方法参数缺少 URI 模板变量 'uuid'”?

django 模板标签缺少 1 个必需的位置参数:值

SocketIO(app)缺少所需的位置参数“模式”[关闭]

TypeError:fit_resample()缺少1个必需的位置参数:'y'[关闭]