 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
N4M Guest
|
Posted: Tue Sep 28, 2004 4:57 pm Post subject: Embedded class' or VC++7 compiler's problem ? |
|
|
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:DATAC++Commonlist.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:DATAC++Commonlist.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/
|
|
| Back to top |
|
 |
Howard Guest
|
Posted: Tue Sep 28, 2004 5:40 pm Post subject: Re: Embedded class' or VC++7 compiler's problem ? |
|
|
"N4M" <dnguyenk (AT) yahoo (DOT) com> wrote
| Quote: | 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
A
When I compile these codes with VC++.NET, there are error messages:
c:DATAC++Commonlist.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:DATAC++Commonlist.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
|
|
| Back to top |
|
 |
N4M Guest
|
Posted: Tue Sep 28, 2004 9:44 pm Post subject: Re: Embedded class' or VC++7 compiler's problem ? |
|
|
"Howard" <alicebt (AT) hotmail (DOT) com> wrote
| Quote: | "N4M" <dnguyenk (AT) yahoo (DOT) com> wrote in message
news:6e8e8a14.0409280857.2efda873 (AT) posting (DOT) google.com...
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
A
When I compile these codes with VC++.NET, there are error messages:
c:DATAC++Commonlist.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:DATAC++Commonlist.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
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Tue Sep 28, 2004 10:03 pm Post subject: Re: Embedded class' or VC++7 compiler's problem ? |
|
|
"N4M" <dnguyenk (AT) yahoo (DOT) com> wrote
| Quote: | "Howard" <alicebt (AT) hotmail (DOT) com> wrote in message
news:<tmh6d.643028$Gx4.275536 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net>...
"N4M" <dnguyenk (AT) yahoo (DOT) com> wrote in message
news:6e8e8a14.0409280857.2efda873 (AT) posting (DOT) google.com...
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
A
When I compile these codes with VC++.NET, there are error messages:
c:DATAC++Commonlist.h(389): error C2143: syntax error : missing
';' before 'list_base<TNValue>::insert'
c:DATAC++Commonlist.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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|