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++_Templates_Function Call - Fatal编程技术网

C++ 访问模板类中的函数

C++ 访问模板类中的函数,c++,templates,function-call,C++,Templates,Function Call,我正在处理以下代码,希望从另一个函数访问OutEdgeCount。我尝试初始化Gate,然后使用Gate.OutEdgeCount()和 大门。上述两种初始化都产生了错误。我是C++新手。如果有人能帮助我或指出任何我可以参考的资源,这将是非常有帮助的 template <typename delay_type, typename error_type, typename power_type, typename mask_type> class Gate: public Gate

我正在处理以下代码,希望从另一个函数访问OutEdgeCount。我尝试初始化Gate,然后使用Gate.OutEdgeCount()和 大门。上述两种初始化都产生了错误。我是C++新手。如果有人能帮助我或指出任何我可以参考的资源,这将是非常有帮助的

template <typename delay_type, typename error_type, typename power_type, typename   mask_type>
class Gate: public Gate_Type<delay_type, error_type, power_type, mask_type>
{
public:
    vector<delay_type> delay;
    vector<error_type> error_probability;
    power_type power;
    vector<mask_type> mask;

    //Constructor
    void GateCopy(Gate<delay_type, error_type, power_type, mask_type> &gate)
    {
        this->gate_name = gate.gate_name;
        this->inout_port_list = gate.inout_port_list;
        this->in_port_list = gate.in_port_list;
        this->out_port_list = gate.out_port_list;
        this->first_in_edge = NULL;
        this->first_out_edge = NULL;
        this->delay.clear();
        this->error_probability.clear();
        this->power = 0;
        this->mask.clear();
        this->parent_block_index = 0;   //the index in sub block list all
        this->active = gate.active;
    }

    int OutEdgeCount(vector<int> out_degree_vec)
    {
        int count = 0;
        Edge<delay_type, error_type> *p_edge = this->first_out_edge;
        if(p_edge == NULL)
        {
            return 0;
        }
        else
        {
            while(p_edge != NULL)
            {
                if(out_degree_vec.at(p_edge->head_index) != -1)
                {
                    count++;
                }
                p_edge = p_edge->same_tail_next;
            }
            return count;
        }
    }
}
void FindAllPaths()
{
   Gate gate;
   ...
 }
模板
门类:公共门类型
{
公众:
矢量延迟;
向量误差概率;
功率型功率;
矢量掩模;
//建造师
无效网关副本(网关和网关)
{
此->门名称=门名称;
此->输入输出端口列表=门。输入输出端口列表;
此->in_port_list=gate.in_port_list;
此->输出端口列表=gate.out端口列表;
此->边中的第一个边=空;
此->先出边=空;
这->delay.clear();
这->错误概率.clear();
这个->功率=0;
这->mask.clear();
this->parent_block_index=0;//子块中的索引列出所有
此->激活=gate.active;
}
int OutEdgeCount(向量输出度向量)
{
整数计数=0;
边*p_边=此->先出边;
if(p_边==NULL)
{
返回0;
}
其他的
{
while(p_边!=NULL)
{
如果(外部度向量在(边缘->头部索引)!=-1)
{
计数++;
}
p_edge=p_edge->same_tail_next;
}
返回计数;
}
}
}
void FindAllPaths()
{
大门;
...
}
错误如下-

graph.h:227:6: error: ‘template<class delay_type, class error_type, class power_type, class mask_type> class graph_space::Gate’ used without template parameters
In file included from main.cpp:3:0:
graph.h: In member function ‘void graph_space::Path<delay_type, error_type, power_type, mask_type>::FindAllPaths(graph_space::Graph<delay_type, error_type, power_type, mask_type>&)’:
graph.h:1797:11: error: missing template arguments before ‘gate’
graph.h:1797:11: error: expected ‘;’ before ‘gate’
graph.h:1895:39: error: ‘gate’ was not declared in this scope
graph.h:1930:38: error: ‘gate’ was not declared in this scope
graph.h:227:6:错误:“模板类图形\u space::Gate”未使用模板参数
在main.cpp中包含的文件中:3:0:
h:在成员函数“void graph\u space::Path::FindAllPaths(graph\u space::graph&)”中:
graph.h:1797:11:错误:“gate”之前缺少模板参数
图h:1797:11:错误:应为“;”“大门”前
graph.h:1895:39:错误:“gate”未在此范围内声明
graph.h:1930:38:错误:“gate”未在此范围内声明

要实例化模板类型,必须提供实例的模板参数。例如,当您创建
std::map
时,必须提供
K
V
的类型,即
std::map allTheFoo

以你为例

Gate<Milliseconds, Exception, Cube, LowerQuadMask> gate;
门;

当然,我刚刚在这里编好了模板类型的名称。

这并没有显示您的错误或错误产生的位置(我想这就是您获得否决票的原因)。此代码中没有初始化任何内容的尝试。请显示
您的代码
错误文本
。希望这样做。请让我知道,如果你想让我添加任何其他内容。我确实这样做了,但我仍然有一个错误。虽然我相信这是因为我传递的属性