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

Embedded class' or VC++7 compiler's problem ?

P: n/a
N4M
Dear,
I have codes as follows:
template<class T>
class A {
public: // embedded class
class E;
public: // types
typedef E TE;
public:// member functions
TE somefunc();
private: // member data
//----------------------------
// embedded class
public:
class E {
//.....//
};
};
//
template<class T>
A<T>::TE A<T>::somefunc() {....}

When I compile these codes with VC++.NET, there are error messages:

c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:\DATA\C++\Common\list.h(389): error C2501:
'list_base<TNValue>::iterator' : missing storage-class or type
specifiers

// TNValue = T, list_base = A, iterator = TE

The same codes are compilled without problem by VC++ 6.

How come?
Is there something not-so-good with my embedded class use? Do you
recommend embedded classes or have other better solutions?

Thansk for your time.
Nguyen Mai
P/S: The same post can be found at .moderated/
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"N4M" <dn******@yahoo.com> wrote in message
news:6e**************************@posting.google.c om...
Dear,
I have codes as follows:
template<class T>
class A {
public: // embedded class
class E;
public: // types
typedef E TE;
public:// member functions
TE somefunc();
private: // member data
//----------------------------
// embedded class
public:
class E {
//.....//
};
};
//
template<class T>
A<T>::TE A<T>::somefunc() {....}

When I compile these codes with VC++.NET, there are error messages:

c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:\DATA\C++\Common\list.h(389): error C2501:
'list_base<TNValue>::iterator' : missing storage-class or type
specifiers

// TNValue = T, list_base = A, iterator = TE


I don't see any "insert" anywhere there??? Perhaps you've snipped out the
relevant code?

Is there a reason you've substituted all the identifiers with these short
names?

Also, why are you using that typedef? You state at the bottom that TE is an
iterator, but your typedef says it's the same as E. I'm confused, to say
the least...

-Howard


Jul 22 '05 #2

P: n/a
N4M
"Howard" <al*****@hotmail.com> wrote in message news:<tm*********************@bgtnsc04-news.ops.worldnet.att.net>...
"N4M" <dn******@yahoo.com> wrote in message
news:6e**************************@posting.google.c om...
Dear,
I have codes as follows:
template<class T>
class A {
public: // embedded class
class E;
public: // types
typedef E TE;
public:// member functions
TE somefunc();
private: // member data
//----------------------------
// embedded class
public:
class E {
//.....//
};
};
//
template<class T>
A<T>::TE A<T>::somefunc() {....}

When I compile these codes with VC++.NET, there are error messages:

c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:\DATA\C++\Common\list.h(389): error C2501:
'list_base<TNValue>::iterator' : missing storage-class or type
specifiers

// TNValue = T, list_base = A, iterator = TE


I don't see any "insert" anywhere there??? Perhaps you've snipped out the
relevant code?

Is there a reason you've substituted all the identifiers with these short
names?

Also, why are you using that typedef? You state at the bottom that TE is an
iterator, but your typedef says it's the same as E. I'm confused, to say
the least...

-Howard


Thanks for your follow-up. The real code is somewhat lengthier, but
the main point is:
1- I use embedded classes (e.g. class E) and template for class A
2- some functions are defined as:
class A<T>::a type defined in A class A<T>::function declared in A()
{....}
//a function declared in A with a return type defined in A

Then VC++.NET gives errors, while VC++.6 compiles. That's strange
since VC++.NET is much more standard conformed (98% vs 86%). I have no
other compilers to check.
But I am unsure it is the good way to use embedded classes,
especiallly along with template.
Hope to receive your comments.
Nguyen Mai
Jul 22 '05 #3

P: n/a

"N4M" <dn******@yahoo.com> wrote in message
news:6e*************************@posting.google.co m...
"Howard" <al*****@hotmail.com> wrote in message
news:<tm*********************@bgtnsc04-news.ops.worldnet.att.net>...
"N4M" <dn******@yahoo.com> wrote in message
news:6e**************************@posting.google.c om...
> Dear,
> I have codes as follows:
> template<class T>
> class A {
> public: // embedded class
> class E;
> public: // types
> typedef E TE;
> public:// member functions
> TE somefunc();
> private: // member data
> //----------------------------
> // embedded class
> public:
> class E {
> //.....//
> };
> };
> //
> template<class T>
> A<T>::TE A<T>::somefunc() {....}
>
> When I compile these codes with VC++.NET, there are error messages:
>
> c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
> ';' before 'list_base<TNValue>::insert'
> c:\DATA\C++\Common\list.h(389): error C2501:
> 'list_base<TNValue>::iterator' : missing storage-class or type
> specifiers
>
> // TNValue = T, list_base = A, iterator = TE
>


I don't see any "insert" anywhere there??? Perhaps you've snipped out
the
relevant code?

Is there a reason you've substituted all the identifiers with these short
names?

Also, why are you using that typedef? You state at the bottom that TE is
an
iterator, but your typedef says it's the same as E. I'm confused, to say
the least...

-Howard


Thanks for your follow-up. The real code is somewhat lengthier, but
the main point is:
1- I use embedded classes (e.g. class E) and template for class A
2- some functions are defined as:
class A<T>::a type defined in A class A<T>::function declared in A()
{....}
//a function declared in A with a return type defined in A

Then VC++.NET gives errors, while VC++.6 compiles. That's strange
since VC++.NET is much more standard conformed (98% vs 86%). I have no
other compilers to check.
But I am unsure it is the good way to use embedded classes,
especiallly along with template.
Hope to receive your comments.
Nguyen Mai


I don't know why people expect their code errors to be fixed when they don't
post the real code, or even compilable code.If your original code was too
lengthy then surely you could have posted a complete example that
illustrates the same problem?

In any case with one minor addition and a few lines added for completeness
your code compiles perfectly well on my copy of VC++ .NET

template<class T>
class A {
public: // embedded class
class E;
public: // types
typedef E TE;
public:// member functions
TE somefunc();
private: // member data
//----------------------------
// embedded class
public:
class E {
//.....//
};
};
//
template<class T>
typename A<T>::TE A<T>::somefunc()
{
return A<T>::TE();
}

int main()
{
A<int> x;
x.somefunc();
}

The minor addition was 'typename' which was missing from your somefunc()
definition.

If you want to check the correctness of your code then a good place to do so
is here http://www.comeaucomputing.com/tryitout/. This online compiler also
has no problem with your corrected code.

john
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.