how to call a template function that takes an enumerated type?

Discussion in 'C++' started by aaragon, Apr 10, 2008.

  1. aaragon

    aaragon Guest

    Hello everyone,

    I run across this problem:

    I have a project that has a class with a template function, something
    like the following:

    class SomeClass {
    ....
    public:
    template <PROPERTY P>
    inline typename PropertyTraits<P,GraphType>::propertyType Map() {
    return boost::get(typename
    PropertyTraits<P,GraphType>::propertyTag(), *g_);
    }
    ....
    };

    so you can see that this function takes an enumerated type:

    enum PROPERTY { POINT, WEIGHT};

    // define local classes
    template <PROPERTY, class Graph>
    class PropertyTraits;

    template <class Graph>
    struct PropertyTraits<POINT,Graph> {
    typedef vertex_point_t PropertyTag;
    typedef typename boost::property_map<Graph, PropertyTag>::type
    PropertyType;
    };
    template <class Graph>
    struct PropertyTraits<WEIGHT,Graph> {
    typedef edge_weight_t PropertyTag;
    typedef typename boost::property_map<Graph, PropertyTag>::type
    PropertyType;
    };


    Now, in some other code, I have a function template that takes as a
    template parameter an object that can be an object of SomeClass.

    class OtherClass {
    ....
    template <class CL>
    void operator()(CL& c) {
    ...
    mvac_.template Map<POINT>()
    ...
    }
    ....
    };

    Now, when I do this, the compiler says:

    domain.h:638: error: 'POINT' was not declared in this scope

    and this is ok because I don't want the code of OtherClass to know
    about any enumerated types or classes in the first project. I tried
    replacing POINT by 0 and it compiles, but then when I have to compile
    the original code I have:

    domain.h:638: error: no matching function for call to 'mvac::mVAC3<2,
    mvac::DomainTraits<2> >::Map()'

    Does anyone knows how can I call this template function? Thank you
    all,

    aa
    aaragon, Apr 10, 2008
    #1
    1. Advertising

  2. aaragon

    Christopher Guest

    On Apr 10, 4:58 pm, aaragon <> wrote:
    > Hello everyone,
    >
    > I run across this problem:
    >
    > I have a project that has a class with a template function, something
    > like the following:
    >
    > class SomeClass {
    > ...
    > public:
    > template <PROPERTY P>
    > inline typename PropertyTraits<P,GraphType>::propertyType Map() {
    > return boost::get(typename
    > PropertyTraits<P,GraphType>::propertyTag(), *g_);
    > }
    > ...
    >
    > };
    >
    > so you can see that this function takes an enumerated type:
    >
    > enum PROPERTY { POINT, WEIGHT};
    >
    > // define local classes
    > template <PROPERTY, class Graph>
    > class PropertyTraits;
    >
    > template <class Graph>
    > struct PropertyTraits<POINT,Graph> {
    > typedef vertex_point_t PropertyTag;
    > typedef typename boost::property_map<Graph, PropertyTag>::type
    > PropertyType;};
    >
    > template <class Graph>
    > struct PropertyTraits<WEIGHT,Graph> {
    > typedef edge_weight_t PropertyTag;
    > typedef typename boost::property_map<Graph, PropertyTag>::type
    > PropertyType;
    >
    > };
    >
    > Now, in some other code, I have a function template that takes as a
    > template parameter an object that can be an object of SomeClass.
    >
    > class OtherClass {
    > ...
    > template <class CL>
    > void operator()(CL& c) {
    > ...
    > mvac_.template Map<POINT>()
    > ...
    > }
    > ...
    >
    > };
    >
    > Now, when I do this, the compiler says:
    >
    > domain.h:638: error: 'POINT' was not declared in this scope
    >
    > and this is ok because I don't want the code of OtherClass to know
    > about any enumerated types or classes in the first project. I tried
    > replacing POINT by 0 and it compiles, but then when I have to compile
    > the original code I have:
    >
    > domain.h:638: error: no matching function for call to 'mvac::mVAC3<2,
    > mvac::DomainTraits<2> >::Map()'
    >
    > Does anyone knows how can I call this template function? Thank you
    > all,
    >
    > aa



    Qualify the enumerated type? include the proper file?
    Depends where it is defined... By what you have written I would assume
    with low confidence that it is global? , but then I doubt you would be
    getting the error.

    You didn't clearly show where the enum was defined, filenames, or
    where the error occured. I don't know where line 638 is in your pasted
    code.
    Christopher, Apr 10, 2008
    #2
    1. Advertising

  3. aaragon

    aaragon Guest

    On Apr 10, 5:37 pm, Christopher <> wrote:
    > On Apr 10, 4:58 pm, aaragon <> wrote:
    >
    >
    >
    > > Hello everyone,

    >
    > > I run across this problem:

    >
    > > I have a project that has a class with a template function, something
    > > like the following:

    >
    > > class SomeClass {
    > > ...
    > > public:
    > > template <PROPERTY P>
    > > inline typename PropertyTraits<P,GraphType>::propertyType Map() {
    > > return boost::get(typename
    > > PropertyTraits<P,GraphType>::propertyTag(), *g_);
    > > }
    > > ...

    >
    > > };

    >
    > > so you can see that this function takes an enumerated type:

    >
    > > enum PROPERTY { POINT, WEIGHT};

    >
    > > // define local classes
    > > template <PROPERTY, class Graph>
    > > class PropertyTraits;

    >
    > > template <class Graph>
    > > struct PropertyTraits<POINT,Graph> {
    > > typedef vertex_point_t PropertyTag;
    > > typedef typename boost::property_map<Graph, PropertyTag>::type
    > > PropertyType;};

    >
    > > template <class Graph>
    > > struct PropertyTraits<WEIGHT,Graph> {
    > > typedef edge_weight_t PropertyTag;
    > > typedef typename boost::property_map<Graph, PropertyTag>::type
    > > PropertyType;

    >
    > > };

    >
    > > Now, in some other code, I have a function template that takes as a
    > > template parameter an object that can be an object of SomeClass.

    >
    > > class OtherClass {
    > > ...
    > > template <class CL>
    > > void operator()(CL& c) {
    > > ...
    > > mvac_.template Map<POINT>()
    > > ...
    > > }
    > > ...

    >
    > > };

    >
    > > Now, when I do this, the compiler says:

    >
    > > domain.h:638: error: 'POINT' was not declared in this scope

    >
    > > and this is ok because I don't want the code of OtherClass to know
    > > about any enumerated types or classes in the first project. I tried
    > > replacing POINT by 0 and it compiles, but then when I have to compile
    > > the original code I have:

    >
    > > domain.h:638: error: no matching function for call to 'mvac::mVAC3<2,
    > > mvac::DomainTraits<2> >::Map()'

    >
    > > Does anyone knows how can I call this template function? Thank you
    > > all,

    >
    > > aa

    >
    > Qualify the enumerated type? include the proper file?
    > Depends where it is defined... By what you have written I would assume
    > with low confidence that it is global? , but then I doubt you would be
    > getting the error.
    >
    > You didn't clearly show where the enum was defined, filenames, or
    > where the error occured. I don't know where line 638 is in your pasted
    > code.


    Ok, the idea is that there are two projects that are completely
    independent of each other. As such, the SomeClass is in the first
    project, with the enumerated type being global. The other project only
    knows about SomeClass through a template parameter, so it can have
    access to SomeClass public typedefs and member functions.

    aa
    aaragon, Apr 10, 2008
    #3
  4. aaragon

    Kai-Uwe Bux Guest

    aaragon wrote:

    > On Apr 10, 5:37 pm, Christopher <> wrote:
    >> On Apr 10, 4:58 pm, aaragon <> wrote:
    >>
    >>
    >>
    >> > Hello everyone,

    >>
    >> > I run across this problem:

    >>
    >> > I have a project that has a class with a template function, something
    >> > like the following:

    >>
    >> > class SomeClass {
    >> > ...
    >> > public:
    >> > template <PROPERTY P>
    >> > inline typename PropertyTraits<P,GraphType>::propertyType Map()
    >> > {
    >> > return boost::get(typename
    >> > PropertyTraits<P,GraphType>::propertyTag(), *g_);
    >> > }
    >> > ...

    >>
    >> > };

    >>
    >> > so you can see that this function takes an enumerated type:

    >>
    >> > enum PROPERTY { POINT, WEIGHT};

    >>
    >> > // define local classes
    >> > template <PROPERTY, class Graph>
    >> > class PropertyTraits;

    >>
    >> > template <class Graph>
    >> > struct PropertyTraits<POINT,Graph> {
    >> > typedef vertex_point_t PropertyTag;
    >> > typedef typename boost::property_map<Graph, PropertyTag>::type
    >> > PropertyType;};

    >>
    >> > template <class Graph>
    >> > struct PropertyTraits<WEIGHT,Graph> {
    >> > typedef edge_weight_t PropertyTag;
    >> > typedef typename boost::property_map<Graph, PropertyTag>::type
    >> > PropertyType;

    >>
    >> > };

    >>
    >> > Now, in some other code, I have a function template that takes as a
    >> > template parameter an object that can be an object of SomeClass.

    >>
    >> > class OtherClass {
    >> > ...
    >> > template <class CL>
    >> > void operator()(CL& c) {
    >> > ...
    >> > mvac_.template Map<POINT>()
    >> > ...
    >> > }
    >> > ...

    >>
    >> > };

    >>
    >> > Now, when I do this, the compiler says:

    >>
    >> > domain.h:638: error: 'POINT' was not declared in this scope

    >>
    >> > and this is ok because I don't want the code of OtherClass to know
    >> > about any enumerated types or classes in the first project. I tried
    >> > replacing POINT by 0 and it compiles, but then when I have to compile
    >> > the original code I have:

    >>
    >> > domain.h:638: error: no matching function for call to 'mvac::mVAC3<2,
    >> > mvac::DomainTraits<2> >::Map()'

    >>
    >> > Does anyone knows how can I call this template function? Thank you
    >> > all,

    >>
    >> > aa

    >>
    >> Qualify the enumerated type? include the proper file?
    >> Depends where it is defined... By what you have written I would assume
    >> with low confidence that it is global? , but then I doubt you would be
    >> getting the error.
    >>
    >> You didn't clearly show where the enum was defined, filenames, or
    >> where the error occured. I don't know where line 638 is in your pasted
    >> code.

    >
    > Ok, the idea is that there are two projects that are completely
    > independent of each other. As such, the SomeClass is in the first
    > project, with the enumerated type being global. The other project only
    > knows about SomeClass through a template parameter, so it can have
    > access to SomeClass public typedefs and member functions.


    The projects cannot be completely independent of one another. In order to
    use SomeClass as a template parameter when a template is instantiated, the
    second project needs to know SomeClass.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Apr 11, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek Ponca

    Enumerated Type in assertion ?

    Marek Ponca, Jan 10, 2005, in forum: VHDL
    Replies:
    2
    Views:
    3,211
    Jonathan Bromley
    Jan 10, 2005
  2. Nick Bassiliades

    Redefining an enumerated attribute type

    Nick Bassiliades, Dec 9, 2005, in forum: XML
    Replies:
    1
    Views:
    432
    Henry S. Thompson
    Dec 12, 2005
  3. Replies:
    1
    Views:
    368
    Henry S. Thompson
    Mar 6, 2006
  4. David
    Replies:
    0
    Views:
    363
    David
    Mar 1, 2006
  5. Replies:
    1
    Views:
    468
    Victor Bazarov
    Jul 20, 2005
Loading...

Share This Page