使用继承类的方法时没有匹配功能

时间:2018-08-24 20:06:12

标签: c++ class inheritance overloading

我有这个班,DAG。 在这里DAG.h

#ifndef DAG_H_INCLUDED
#define DAG_H_INCLUDED

#include <fstream>
#include "types.h"

using namespace std;

template <typename R>
using Leaf=U_IR<R>; 
//typedef U_IR<R> Leaf;//non-empty leaf in DAG

typedef vector<N> ListN;

template <typename R> 
struct Node//non-empty node in DAG
{
    vector < R > x; //incresing sequence in R of size #x>0
    ListN ux;//sequences of #x links to level below in DAG
    ListN u; //sequences of #x-1 links to level below in DAG
    friend bool operator==(const Node<R>&X1, const Node<R>&X2)
    {
        return X1.x==X2.x &&X1.ux==X2.ux &&X1.u==X2.u;
    };
};

template <typename R>
using Leaves=vector < Leaf<R> >;
//typedef vector < Leaf<R> > Leaves;//set of nodes at level 0 in DAG

template <typename R> 
using Nodes=vector<Node <R> >;
//typedef vector < Node<R> > Nodes;//set of nodes at a given level in DAG

template <typename R> 
class DAG
{
private:
    Leaves<R> leaf;  //set of non-empty nodes at level 0, G empty if #leaf=0
    vector < Nodes<R> > nodes;//nodes[l] set of non-empty nodes at level l+
    //memoization
    vector<vector <vector <CMP> > > C;
    //C[l][j][i] comparison of i and j at level l, with i<j ('?' if not computed yet)
    vector<vector <vector <N> > > U;
    //U[l][j][i] result of union of i and j  at level l, with i<j (0 if not computed yet)
    N add_leaf(const Leaf<R>&);//prevent duplication
    N add_node(const Node<R>&, N l);//prevent duplication
    bool cover(const BR<R>&,ListN&,N l) const;
    bool cover(R,R,const Node<R>&,ListN&) const;
    CMP cmp(N,N,N l);//comparison of nodes at level l
    void cmp(const Node<R> &, const Node<R> &, CMP &, N l);
    N make(const BR<R>&,N l);//make at level l
    N sum(N,N,N l);//union of nodes at level l
    Node<R> sum(const Node<R> & X1, const Node<R> & X2, N l);
public:
    DAG(N d);//dimension d>0
    void print() const;//print DAG (for debug purposes)
    void print_test(ostream &cout) const;//print for testing
    void print2(N) const;//print subsets of the plane with integer bounds
    N dim() const;
    N empty() const;
    bool cover(const BR<R>&,N) const;
    CMP cmp(N,N);
    N make(const BR<R>&);
    N sum(N,N);
};

#include "DAG.tpp"
#include "DAG-sum.tpp"
#include "DAG-cover.tpp"
#include "DAG-make.tpp"
#include "DAG-cmp.tpp"


#endif  // DAG_H_INCLUDED

还有DAG-hypro.h中的继承类DAG_hypro,在其中添加了两个方法:

#ifndef DAG_Hypro_INCLUDED
#define DAG_Hypro_INCLUDED

#include <fstream>
#include "types.h"
#include "DAG.h"
#include "representations/GeometricObject.h"
#include "datastructures/Point.h"
#include "datastructures/Halfspace.h"

using namespace std;

template <typename R>
class DAG_hypro : public DAG<R>{
private:

public:
    bool cover(const hypro::Box<R>&,N) const;
    N make(const hypro::Box<R>&);
};

#include "DAG-cover-hypro.tpp"
#include "DAG-make-hypro.tpp"


#endif

我有两个.tpp实现了这些新方法。这是其中之一:DAG-make-hypro.tpp

#include <iostream> //for debugging
#include "functions.h"
#include "DAG-hypro.h"

template <typename R>
N DAG_hypro<R>::make(const hypro::Box<R>& B)
{
    /*mybox*/
    vector<carl::Interval<R>> temp=B.boundaries();
    int d = temp.size();
    BR<R> myBox(d);
    for (int j=0;j<d;j++){
        IR<R> interval=IR<R>(temp[j].lower(),temp[j].upper());  
        myBox.x[j]=interval;
    }

    return make(myBox,dim()-1);
}

如您所见,它返回了另一个make方法,但是这次不一样。我以为此调用将调用从DAG类继承的make方法,但出现此错误:

> In file included from
> /home/gianluca/Scrivania/template/DAG-hypro.h:22:0,
>                  from /home/gianluca/Scrivania/template/main-GC.cpp:5: /home/gianluca/Scrivania/template/DAG-cover-hypro.tpp: In member
> function ‘bool DAG_hypro<R>::cover(hypro::Box<R>&, N) const’:
> /home/gianluca/Scrivania/template/DAG-cover-hypro.tpp:20:30: error: no
> matching function for call to ‘dim()’
>      return cover(myBox,C,dim()-1);

如何调用继承的dim()方法?

我还有另一个问题。在main内部,我尝试使用DAG_hypro<R> G(d);创建DAG_hypro类型的对象,然后得到

> /home/gianluca/Scrivania/template/main-GC.cpp: In function ‘int
> main()’: /home/gianluca/Scrivania/template/main-GC.cpp:29:21: error:
> no matching function for call to ‘DAG_hypro<__gmp_expr<__mpq_struct
> [1], __mpq_struct [1]> >::DAG_hypro(N&)’
>      DAG_hypro<R> G(d);
>                      ^ In file included from /home/gianluca/Scrivania/template/main-GC.cpp:5:0:
> /home/gianluca/Scrivania/template/DAG-hypro.h:14:7: note: candidate:
> DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]>
> >::DAG_hypro(const DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >&)  class DAG_hypro : public DAG<R>{
>        ^ /home/gianluca/Scrivania/template/DAG-hypro.h:14:7: note:   no known conversion for argument 1 from ‘N {aka unsigned int}’ to
> ‘const DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >&’
> /home/gianluca/Scrivania/template/DAG-hypro.h:14:7: note: candidate:
> DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]>
> >::DAG_hypro(DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >&&) /home/gianluca/Scrivania/template/DAG-hypro.h:14:7: note:   no known conversion for argument 1 from ‘N {aka unsigned int}’ to
> ‘DAG_hypro<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >&&’

0 个答案:

没有答案
相关问题