Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-04-10 13:43:45


Sebastian Weber <sebastian.weber_at_[hidden]> writes:

> Hi!
>
>> > /home/sebi/projects/diplom/src/boost_1_33_1/boost/graph/adjacency_list_io.hpp:151: error: 'boost::GraphParser<Graph_t, VertexProperty, EdgeProperty, VertexPropertySubset, EdgePropertySubset>::operator()(std::istream&) [with Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>, VertexProperty = boost::no_property, EdgeProperty = boost::no_property, VertexPropertySubset = boost::no_property, EdgePropertySubset = boost::no_property]::State' uses local type 'boost::GraphParser<Graph_t, VertexProperty, EdgeProperty, VertexPropertySubset, EdgePropertySubset>::operator()(std::istream&) [with Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>, VertexProperty = boost::no_property, EdgeProperty =
> boos
>> > t::no_property, VertexPropertySubset = boost::no_property, EdgePropertySubset = boost::no_
>> > property]::State'
>>
>> This says that the GraphParser class -- which you apparently defined
>> in namespace boost; naughty, naughty! -- has an operator() with a
>
> Well, the GraphParser-class is placed in adjacency_list_io within the
> namespace boost, that wasn't me.

I don't know what you mean. Who was it?
I certainly see "boost::GraphParser" in the error message above, so
where does adjacency_list_io come into it?

>> locally-defined type State, and you're trying to pass an instance of
>> that type off to a function template.
>>
>> It's a rule of C++ that you can't instantiate templates on
>> function-local types.
>
> Oh, as I have learned template-stuff by doing it and not reading a book
> (which I probably should have), I'm actually not that familiar with
> this. In short: I don't understand neither the problem nor do I know how
> to fix it.

Simple: don't define the State type locally to the function.

If the type depends on some template parameters of the function, e.g.

   class State : public foo<VertexProperty> { ... };

you can just define it outside the function as:

   template <class VertexProperty> class State_
     : public foo<VertexProperty>
   { ... };

and then in the function:

   typedef State_<VertexProperty> State;

>> Learning to read your compiler's error messages can be difficult, but
>> it is well worth the effort. STLFilt can help to make them more
>> approachable (http://www.bdsoft.com)
>
> Well, I looked there, but STLFilt doesn't support g++ 4.0 (to be exact:
> g++-4.0 (GCC) 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)).

I use STLFilt with g++-4 with success.

> And gcc-3.3 (and 3.4) DOES compile my code without any complaints.

Not to be blunt, but so what? That doesn't make your code right.

> Any other ideas?

Not really; I told you what the problem was. I hope it helped,
because there are no other answers AFAIK.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net