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

A

aaragon

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
 
C

Christopher

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.
 
A

aaragon

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
 
K

Kai-Uwe Bux

aaragon said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top