473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

iterator for derived class of std::vector

I am compiling with g++ the fol. class:

template<typename E>

class C_vector_ : public std::vector<E>

{

private:

typedef std::vector<EVBASE_;

public:

void stream(void)

{

VBASE_::const_iterator it;

f or( it=this->begin(); it< this->end(); it++ )

cout << endl << *it;

return

}

};//eoClass: C_Vector

At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">

With MSC V6. there is no compiler error.

Regards Thomas
Jan 23 '07 #1
7 2513
Thomas wrote:
I am compiling with g++ the fol. class:

template<typename E>

class C_vector_ : public std::vector<E>

{

private:

typedef std::vector<EVBASE_;

public:

void stream(void)

{

VBASE_::const_iterator it;

f or( it=this->begin(); it< this->end(); it++ )

cout << endl << *it;

return

}

};//eoClass: C_Vector

At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">
See this FAQ:

http://parashift.com/c++-faq-lite/te...html#faq-35.18

But std::vector is not intended as a base class (it's destructor is not
virtual, for instance). Better practice would be to instead make a
wrapper class or, if you just want streaming capability, a
free-standing function (perhaps ostream& operator<<( ostream&, const
vector<T>& ) ).

Cheers! --M

Jan 23 '07 #2
Thomas wrote:
>
VBASE_::const_iterator it;
typename VBASE_::const_iterator it;

Qualified dependent type.
At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">

With MSC V6. there is no compiler error.
V6 is old and busted. G++ is new hotness.
Jan 23 '07 #3
"Ron Natalie" <ro*@spamcop.netschrieb im Newsbeitrag
news:45*********************@news.newshosting.com. ..
Thomas wrote:
>>
VBASE_::const_iterator it;
typename VBASE_::const_iterator it;

Qualified dependent type.
>At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">

With MSC V6. there is no compiler error.
V6 is old and busted. G++ is new hotness.
Thank You Ron, that was the looked-for constructive contribution.
Jan 24 '07 #4

"mlimber" <ml*****@gmail.comschrieb im Newsbeitrag
news:11**********************@s48g2000cws.googlegr oups.com...
Thomas wrote:
>I am compiling with g++ the fol. class:

template<typename E>

class C_vector_ : public std::vector<E>

{

private:

typedef std::vector<EVBASE_;

public:

void stream(void)

{

VBASE_::const_iterator it;

f or( it=this->begin(); it< this->end(); it++ )

cout << endl << *it;

return

}

};//eoClass: C_Vector

At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">

See this FAQ:

http://parashift.com/c++-faq-lite/te...html#faq-35.18

But std::vector is not intended as a base class (it's destructor is not
virtual, for instance). Better practice would be to instead make a
wrapper class or, if you just want streaming capability, a
free-standing function (perhaps ostream& operator<<( ostream&, const
vector<T>& ) ).

Cheers! --M
Thank You --M, but can You tell me please waht do You mean with "a wrapper
class"?

Best regards Thomas
Jan 24 '07 #5

"mlimber" <ml*****@gmail.comschrieb im Newsbeitrag
news:11**********************@s48g2000cws.googlegr oups.com...
Thomas wrote:
>I am compiling with g++ the fol. class:

template<typename E>

class C_vector_ : public std::vector<E>

{

private:

typedef std::vector<EVBASE_;

public:

void stream(void)

{

VBASE_::const_iterator it;

f or( it=this->begin(); it< this->end(); it++ )

cout << endl << *it;

return

}

};//eoClass: C_Vector

At <VBASE_::const_iterator it;the compiler shows the error message <

error: expected `;' before "it">

See this FAQ:

http://parashift.com/c++-faq-lite/te...html#faq-35.18

But std::vector is not intended as a base class (it's destructor is not
virtual, for instance). Better practice would be to instead make a
wrapper class or, if you just want streaming capability, a
free-standing function (perhaps ostream& operator<<( ostream&, const
vector<T>& ) ).

Cheers! --M
Thank You --M,

for a long time, I did not derive classes from base classes, which do not
have a virtual destructor (and I detest it today), but sometimes I do not
know how to work around. But as far as I know, a virtual destructor is not
needed in all cases. F.i., is it imperative to have a virtual destructor in
the base class, if objekts of the derived class will only be deleted via a
pointer to that objects (not to a base-class-pointer)?

Best regards Thomas
Jan 24 '07 #6


On Jan 24, 1:01 pm, "Thomas" <Tho...@Schmid-Zettler.dewrote:
"mlimber" <mlim...@gmail.comschrieb im Newsbeitragnews:11**********************@s48g2000c ws.googlegroups.com...
Thomas wrote:
I am compiling with g++ the fol. class:
template<typename E>
class C_vector_ : public std::vector<E>
{
private:
typedef std::vector<EVBASE_;
public:
void stream(void)
{
VBASE_::const_iterator it;
f or( it=this->begin(); it< this->end(); it++ )
cout << endl << *it;
return
}
};//eoClass: C_Vector
At <VBASE_::const_iterator it;the compiler shows the error message <
error: expected `;' before "it">
See this FAQ:
http://parashift.com/c++-faq-lite/te...html#faq-35.18
But std::vector is not intended as a base class (it's destructor is not
virtual, for instance). Better practice would be to instead make a
wrapper class or, if you just want streaming capability, a
free-standing function (perhaps ostream& operator<<( ostream&, const
vector<T>& ) ).
Cheers! --MThank You --M,

for a long time, I did not derive classes from base classes, which do not
have a virtual destructor (and I detest it today), but sometimes I do not
know how to work around. But as far as I know, a virtual destructor is not
needed in all cases. F.i., is it imperative to have a virtual destructor in
the base class, if objekts of the derived class will only be deleted via a
pointer to that objects (not to a base-class-pointer)?

Best regards Thomas
they like to abuse the rule: "base classes must have a virtual
destructor" due to safety

but classes that do not have virtual functions seldom need virtual
destructors. so, I like the gcc warning: "class has virtual functions,
but does not have virtual destructor"

you can safely inherit from vector<Tif you do not make deletion from
base (e.g.: raw and smart pointers). period

Jan 25 '07 #7

"Diego Martins" <jo********@gmail.comschrieb im Newsbeitrag
news:11*********************@a75g2000cwd.googlegro ups.com...
>

On Jan 24, 1:01 pm, "Thomas" <Tho...@Schmid-Zettler.dewrote:
>"mlimber" <mlim...@gmail.comschrieb im
Newsbeitragnews:11**********************@s48g2000 cws.googlegroups.com...
Thomas wrote:
I am compiling with g++ the fol. class:
>template<typename E>
>class C_vector_ : public std::vector<E>
> {
> private:
> typedef std::vector<EVBASE_;
> public:
> void stream(void)
> {
> VBASE_::const_iterator it;
> f or( it=this->begin(); it< this->end(); it++ )
> cout << endl << *it;
> return
> }
> };//eoClass: C_Vector
>At <VBASE_::const_iterator it;the compiler shows the error message
<
>error: expected `;' before "it">
See this FAQ:
>http://parashift.com/c++-faq-lite/te...html#faq-35.18
But std::vector is not intended as a base class (it's destructor is not
virtual, for instance). Better practice would be to instead make a
wrapper class or, if you just want streaming capability, a
free-standing function (perhaps ostream& operator<<( ostream&, const
vector<T>& ) ).
Cheers! --MThank You --M,

for a long time, I did not derive classes from base classes, which do not
have a virtual destructor (and I detest it today), but sometimes I do not
know how to work around. But as far as I know, a virtual destructor is
not
needed in all cases. F.i., is it imperative to have a virtual destructor
in
the base class, if objekts of the derived class will only be deleted via
a
pointer to that objects (not to a base-class-pointer)?

Best regards Thomas

they like to abuse the rule: "base classes must have a virtual
destructor" due to safety

but classes that do not have virtual functions seldom need virtual
destructors. so, I like the gcc warning: "class has virtual functions,
but does not have virtual destructor"

you can safely inherit from vector<Tif you do not make deletion from
base (e.g.: raw and smart pointers). period
Hello Diego,
I agree absolutely and IMHO one can inherit also from a base class having no
virtual destructor, if the derived class does not create objects on the
heap.
But always try to respect Your mentioned safety rules.

Nevertheless, I do not know why I get the compiler error in the original
stated problem.

Regards Thomas
Jan 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in...
4
by: enzo | last post by:
hi all, i don't understand what's wrong: 1) std::vector<double> p(10); doesn't compile:
5
by: Ernst Murnleitner | last post by:
Hello, is it possible to derive from std::vector and derive also its iterator? If I do it like in the example below, I get a problem when I need the begin of the vector: begin() returns the...
3
by: Ken Cecka | last post by:
This is a contrived example to demonstrate a syntax problem I'm struggling with: #include <vector> template <typename T> class Class { };
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
8
by: Lionel B | last post by:
On my platform I find that the std::vector<boolspecialisation incurs a significant performance hit in some circumstances (when compared, say, to std::vector<intprogrammed analagously). Is it...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.