开发者

inheritance, policy mixed with templates

I want to do something as the following.

I have a class as follows with some elements which are not our concern right now.

template<class A>
class Domain
{

};

My issue is, I want some new objects to be members of this class. But I cannot specify them in this definition. I have to specify it in some other file. My first thought was using inheritance as follows:

template<class G,class ctype>
class Data
{
  public:
     Data(G& g_);
  protected:
     std::vector<ctype> data1;
};

and then

template<class A>
class Domain : public Data<A,A::ctype>
{
    public:
       Domain(A& a);
       void writeData(data1);
};
template<class A>
Domain<A>::Domain(A& a)
{

}

however, I've not been able to get it to compile. Any suggestions how to go about this? Any method on how to do this in a cleaner way?

the full program is the following. Its only in the header file. I haven't created an instance yet. The program is

28   template<class GV, class Data>
29   class System : public Data<GV,GV::ctype>
30   {
31     private:
32      typedef Dune::VTKWriter<GV> VTKWriter;
33      GV& gv_;
34      VTKWriter vtkwriter_;
35  
36    public:
37      System(GV& gv);  
38      void writeSystemInfo(std::string outfile);
39   };
40  
41   template<class GV, class Data>
42   System<GV,Data>::System(GV& gv) : gv_(gv) , vtkwriter_(gv)
43   {
44   }
45 
46   template<class GV,class Data>
47   void System<GV,Data>::writeSystemInfo(std::string outfile)
48   {
49     Data::addDatatoVTK();
50     vtkwriter_.write(outfile, Dune::VTKOptions::binaryappended);
51   }

and the errors are

../dune/simulationlab/system/system.hh:29:29: error: expected template-name before ‘<’ token
../dune/simulationlab/system/system.hh:29:29: error: expected ‘{’ before ‘<’ token
../dune/simulationlab/system/system.hh:29:29: error: expected unqualified-id before ‘<’ token
../dune/simulationlab/system/system.hh:46:33: error: invalid use of incomplete type ‘cla开发者_C百科ss Dune::System<GV, Data>’
../dune/simulationlab/system/system.hh:29:9: error: declaration of ‘class Dune::System<GV, Data>’
../dune/simulationlab/system/system.hh:52:60: error: invalid use of incomplete type ‘class Dune::System<GV, Data>’
../dune/simulationlab/system/system.hh:29:9: error: declaration of ‘class Dune::System<GV, Data>’


A::ctype is seen as a member call, not a type. You should use the typename keyword:

template<class A>
class Domain : public Data<A,typename A::ctype>
{
    public:
       Domain(A& a);
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜