Salt_Peter wrote:
toton wrote:
Hi,
If I inherit some template class to form another template class,
do the member functions from the parent class automatically comes to
the child class, or I need to write something like
using boost::vector<T,Alloc>::begin; etc (to get begin() and other
functions).
That depends. are the members private, protected or public?
Is the base class a struct or a class?
Was inheritance a public or private inheritance?
And so on... why don't you put together a short example with no
implementation details.
Here is an example I was trying to compile, and spending hard hours :(
..
The example uses a few boost library though, and have a second problem
Here I was using boost::range mostly. But I failed to compile it using
VS7.1 and VS2005. They were both saying some type conversion problem
(Though I don't find any, it it is hard to debug templates), while
mingw was complaining about using thing, and after that it compiles
finely.
Here is the complete source code (boost rc 1_34 is used , along with
one sandbox circular_buffer class )
#include <iterator>
#include <memory>
#include <vector>
#include <iostream>
using namespace std;
#include <boost/circular_buffer.hpp>
#include <boost/range.hpp>
template<typename T>
class range_vector : public boost::circular_buffer<T>{
public:
typedef boost::sub_range<range_vectorrange;
typedef boost::sub_range<const range_vectorconst_range;
typedef typename boost::circular_buffer<T>::size_type size_type;
///mingw complains, doesn't compile without this.
using boost::circular_buffer<T>::begin; ///mingw complains without
this. doesn't compile
range_vector(size_type capacity) :
boost::circular_buffer<T>(capacity){}
range get_range(size_type from,size_type to){
std::cout<<"range"<<std::endl;
return range(begin()+from,begin()+to);
}
const_range get_range(size_type from,size_type to)const{
std::cout<<"const range"<<std::endl;
return const_range(begin()+from,begin()+to);
}
};
typedef range_vector<intrvi;
int main() {
rvi v(9);
int x[] = {0,1,2,3,4,5,6,7,8};
v.insert(v.end(),x,x+9);
const rvi& cv = v;
std::copy(v.begin(),v.end(),std::ostream_iterator< int>(std::cout,"
"));
std::cout<<std::endl;
boost::sub_range<rvir(v.begin()+1,v.begin()+5);
rvi::range r0(v.begin()+1,v.begin()+5);
rvi::range r1(v.get_range(1,5));
r[0] = 100;
copy(r.begin(),r.end(),std::ostream_iterator<int>( std::cout," "));
std::cout<<std::endl;
boost::sub_range<const rvicr0(v.begin()+1,v.begin()+5);
rvi::const_range cr1(v.begin()+1,v.begin()+5);
rvi::const_range cr2(v.get_range(1,5));
std::cout<<cr0[0]<<std::endl;
rvi::const_range cr3 = v.get_range(1,5);
copy(cr3.begin(),cr3.end(),std::ostream_iterator<i nt>(std::cout,"
"));
std::cout<<std::endl;
boost::sub_range<const rvicr4(cv.begin()+1,cv.begin()+5);
rvi::const_range cr5(cv.get_range(1,5));
copy(cr4.begin(),cr4.end(),std::ostream_iterator<i nt>(std::cout,"
"));
std::cout<<std::endl;
//copy(cr2.begin(),cr2.end(),std::ostream_iterator<i nt>(std::cout,"
"));
std::cout<<std::endl;
std::cout<<std::endl;
return 0;
}
But with that addition everything works for MinGW. (gcc version 3.4.5
mingw build)
VS 2003 or 2005 don't give any error or warning without them . but it
fails to compile
saying
e:\boost_1_33_1\boost\range\iterator_range.hpp(60) : error C2440: 'type
cast' : cannot convert from 'boost::range_iterator<C>::type' to
'boost::range_iterator<C>::type'
with
[
C=const boost::sub_range<range_vector<int>>
]
and
[
C=range_vector<int>
]
Which I am not sure why it can't.
Surprisingly, just changing parent class boost::circular_buffer<Tto
std::vector<Tthe code works.
To cover all the possibilities one could write a book on the subject.
Similarly all the base class typedef's automatically come to the
derived class or I need to explicitly say
typedef typename std::vector<T, Alloc>::pointer pointer;
What is according to standard ?
Thanks.