By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

iterator for derived class of std::vector

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a

"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

P: n/a

"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

P: n/a


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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.