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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/154.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++_Templates_Boost Spirit Qi - Fatal编程技术网

C++ 不允许使用类型名称

C++ 不允许使用类型名称,c++,templates,boost-spirit-qi,C++,Templates,Boost Spirit Qi,我正在编写一个解析器,并试图插入一个迭代器作为模板。 当我编写模板时,代码按预期编译。我想我应该能够删除默认值,所以我想编写模板。我想这应该是可以的,因为我以后专门化了模板。但是,编译时不会出现以下错误:不允许使用错误(活动)类型名称 这是怎么回事?为什么我会犯这个错误 下面是示例代码: #include <string> #include <boost\spirit\include\qi.hpp> namespace qi = boost::spirit::qi;

我正在编写一个解析器,并试图插入一个迭代器作为模板。 当我编写
模板
时,代码按预期编译。我想我应该能够删除默认值,所以我想编写
模板
。我想这应该是可以的,因为我以后专门化了模板。但是,编译时不会出现以下错误:
不允许使用错误(活动)类型名称

这是怎么回事?为什么我会犯这个错误

下面是示例代码:

#include <string>
#include <boost\spirit\include\qi.hpp>

namespace qi = boost::spirit::qi;

template<typedef class Iterator>  //<-- This does not compile
//template<typedef class Iterator = std::string::iterator>  //<-- This would compile
class Rules_template
{
private:
    typedef qi::rule<Iterator> skipper_rule;
    typedef qi::rule<Iterator> line_rule;
    typedef qi::rule<Iterator, std::string(), skipper_rule> string_rule;
    typedef qi::rule<Iterator, float, skipper_rule> float_rule;
    line_rule endofline = qi::lit("\r\n") | qi::lit("\n\r") | qi::lit('\n');
    skipper_rule skip = qi::lit(' ') | qi::lit('\t') | qi::lit('\f') | qi::lit('\v') | (qi::lit('\\') >> endofline);
    string_rule comment = qi::lexeme['#' >> *(qi::char_ - qi::char_('\n') - qi::char_('\r')) >> endofline];
public:
    string_rule & Comment() { return comment; }
    skipper_rule & Skip() { return skip; }
};

static Rules_template<std::string::iterator> Rules_str;

void CHECK(bool b)
{
    if (b)
        std::cout << "check ok" << std::endl;
    else
        std::cout << "check not ok" << std::endl;
}

int main(int argc, char ** argv)
{
    std::string test = "#This is a comment\n";
    std::string expect = "This is a comment";
    std::string actual;
    auto it = test.begin();
    CHECK(true == qi::phrase_parse(it, test.end(), Rules_str.Comment(), Rules_str.Skip(), actual));
    CHECK(it == test.end());
    CHECK(expect.compare(actual) == 0);
}
#包括
#包括
名称空间qi=boost::spirit::qi;
模板//endofline);
string#rule comment=qi::lexeme['#'>>*(qi::char#-qi::char#('\n')-qi::char#('\r'))>>endofline];
公众:
string_rule&Comment(){return Comment;}
skipper_规则&Skip(){return Skip;}
};
静态规则\u模板规则\u str;
无效检查(bool b)
{
如果(b)

std::cout当我使用code::Blocks编译器编译此代码时,会出现以下错误:

typedef declaration invalid in parameter declaration
当我将模板声明更改为:

template<class Iterator>

当我使用code::Blocks编译器编译此代码时,出现以下错误:

typedef declaration invalid in parameter declaration
当我将模板声明更改为:

template<class Iterator>

<代码>模板<代码>在标准C++中肯定是语法错误。您确定这是原始代码吗?您是说使用<代码>类型名< /C> >?这里我用VS2015对这个代码进行编译,这不是“原始”。我写了一个最小的例子来重现这个错误,只是为了显示它。我测试了这个行为,它的行为和我的应用程序完全一样。<代码>模板>代码>绝对是标准C++中的语法错误。你确定这是原始代码吗?你是说使用<代码>类型名< /C>?它是编译的。这不是“原始的”,我写了一个最小的示例来重新创建错误,只是为了在这里显示它。我测试了它,以确保其行为与我的应用程序中的行为完全相同。