Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to call a template function that takes an enumerated type?

Reply
Thread Tools

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

 
 
aaragon
Guest
Posts: n/a
 
      04-10-2008
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>:ropertyType Map() {
return boost::get(typename
PropertyTraits<P,GraphType>:ropertyTag(), *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:roperty_map<Graph, PropertyTag>::type
PropertyType;
};
template <class Graph>
struct PropertyTraits<WEIGHT,Graph> {
typedef edge_weight_t PropertyTag;
typedef typename boost:roperty_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:omainTraits<2> >::Map()'

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

aa
 
Reply With Quote
 
 
 
 
Christopher
Guest
Posts: n/a
 
      04-10-2008
On Apr 10, 4:58 pm, aaragon <(E-Mail Removed)> 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>:ropertyType Map() {
> return boost::get(typename
> PropertyTraits<P,GraphType>:ropertyTag(), *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:roperty_map<Graph, PropertyTag>::type
> PropertyType;};
>
> template <class Graph>
> struct PropertyTraits<WEIGHT,Graph> {
> typedef edge_weight_t PropertyTag;
> typedef typename boost:roperty_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:omainTraits<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.
 
Reply With Quote
 
 
 
 
aaragon
Guest
Posts: n/a
 
      04-10-2008
On Apr 10, 5:37 pm, Christopher <(E-Mail Removed)> wrote:
> On Apr 10, 4:58 pm, aaragon <(E-Mail Removed)> 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>:ropertyType Map() {
> > return boost::get(typename
> > PropertyTraits<P,GraphType>:ropertyTag(), *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:roperty_map<Graph, PropertyTag>::type
> > PropertyType;};

>
> > template <class Graph>
> > struct PropertyTraits<WEIGHT,Graph> {
> > typedef edge_weight_t PropertyTag;
> > typedef typename boost:roperty_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:omainTraits<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
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      04-10-2008
aaragon wrote:

> On Apr 10, 5:37 pm, Christopher <(E-Mail Removed)> wrote:
>> On Apr 10, 4:58 pm, aaragon <(E-Mail Removed)> 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>:ropertyType Map()
>> > {
>> > return boost::get(typename
>> > PropertyTraits<P,GraphType>:ropertyTag(), *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:roperty_map<Graph, PropertyTag>::type
>> > PropertyType;};

>>
>> > template <class Graph>
>> > struct PropertyTraits<WEIGHT,Graph> {
>> > typedef edge_weight_t PropertyTag;
>> > typedef typename boost:roperty_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:omainTraits<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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
specialized member function takes precedence over generic template member function bluekite2000@gmail.com C++ 1 07-20-2005 08:58 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments