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

N

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/
 
H

Howard

N4M said:
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
 
N

N4M

Howard said:
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
 
J

John Harrison

N4M said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top