 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nariman Guest
|
Posted: Fri Feb 20, 2004 5:14 pm Post subject: deque C2027 error |
|
|
The following piece of example code compiles under VC++6, however not
under .NET:
typedef deque<T> D;
class T
{
int i, j;
D c;
}
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
I know the problem is that instantiating deque requires a complete
type and
class T isn't yet a complete type. How can I modify the code so that
it compiles under .NET?
Thanks,
Nari
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Sat Feb 21, 2004 4:22 am Post subject: Re: deque C2027 error |
|
|
In message <dbe33dd6.0402192258.6ae79b28 (AT) posting (DOT) google.com>, Nariman
<nariman_sg (AT) yahoo (DOT) com> writes
| Quote: | The following piece of example code compiles under VC++6, however not
under .NET:
typedef deque<T> D;
class T
{
int i, j;
D c;
}
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
I know the problem is that instantiating deque requires a complete
type and
class T isn't yet a complete type. How can I modify the code so that
it compiles under .NET?
|
Well a more fundamental problem is how you intend to have a type that
contains a deque of itself. I believe we explicitly outlawed such soon
after Andy Koenig realised that it was technically possible providing
the container was empty.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Sat Feb 21, 2004 10:40 am Post subject: Re: deque C2027 error |
|
|
Nariman wrote:
| Quote: | The following piece of example code compiles under VC++6,
|
No it doesn't.
| Quote: | however not under .NET:
typedef deque<T> D;
class T
{
int i, j;
D c;
}
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
I know the problem is that instantiating deque requires a complete
type and class T isn't yet a complete type. How can I modify the
code so that it compiles under .NET?
|
You must define class T before instantiating any template from the
standard library for which it is a template argument. The standard
says that the result of not doing this is undefined behaviour!
Since you cannot do that in this case I think you will have to use a
std::deque<T *> instead. Also see <http://groups.google.com/groups?
threadm=9200fe91.0402170837.7f182aab%40posting.google.com> (you will
have to paste those two lines together).
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alexander J. Oss Guest
|
Posted: Sat Feb 21, 2004 11:04 am Post subject: Re: deque C2027 error |
|
|
"Nariman" <nariman_sg (AT) yahoo (DOT) com> wrote
| Quote: | The following piece of example code compiles under VC++6, however not
under .NET:
typedef deque<T> D;
class T
{
int i, j;
D c;
}
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
|
I'm not sure, but I think you just need a forward declaration:
class T;
before the typedef.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
John Potter Guest
|
Posted: Sat Feb 21, 2004 7:19 pm Post subject: Re: deque C2027 error |
|
|
On 20 Feb 2004 23:22:44 -0500, Francis Glassborow
<francis (AT) robinton (DOT) demon.co.uk> wrote:
| Quote: | In message <dbe33dd6.0402192258.6ae79b28 (AT) posting (DOT) google.com>, Nariman
[email]nariman_sg (AT) yahoo (DOT) com[/email]> writes
The following piece of example code compiles under VC++6, however not
under .NET:
typedef deque<T> D;
|
This never should have worked.
| Quote: | class T
{
int i, j;
D c;
|
deque<T> c;
This is undefined but that allows working fine.
| Quote: | }
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
I know the problem is that instantiating deque requires a complete
type and
class T isn't yet a complete type. How can I modify the code so that
it compiles under .NET?
Well a more fundamental problem is how you intend to have a type that
contains a deque of itself.
|
Simple, use gcc.
| Quote: | I believe we explicitly outlawed such soon
after Andy Koenig realised that it was technically possible providing
the container was empty.
|
The fundamental problem is why the standard makes it undefined when
compilers like gcc handle all standard containers.
struct S {
deque<S> d;
list<S> l;
map<S, S> m;
set<S> s;
vector<S> v;
};
bool operator< (S const& lhs, S const& rhs) {
return lhs.v < rhs.v;
}
int main () {
S s;
s.d.push_back(s);
s.l.push_back(s);
s.m[s] = s;
s.s.insert(s);
s.v.push_back(s);
}
John
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alexander J. Oss Guest
|
Posted: Sun Feb 22, 2004 1:44 am Post subject: Re: deque C2027 error |
|
|
"Alexander J. Oss" <alex (AT) alexoss (DOT) net> wrote
| Quote: | I'm not sure, but I think you just need a forward declaration:
class T;
before the typedef.
|
Please ignore my ignorant babbling.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Sun Feb 22, 2004 10:50 am Post subject: Re: deque C2027 error |
|
|
"John Potter" <jpotter (AT) falcon (DOT) lhup.edu> wrote in message:
| Quote: | On 20 Feb 2004 23:22:44 -0500, Francis Glassborow
[email]francis (AT) robinton (DOT) demon.co.uk[/email]> wrote:
I believe we explicitly outlawed such soon
after Andy Koenig realised that it was technically possible
providing
the container was empty.
The fundamental problem is why the standard makes it undefined when
compilers like gcc handle all standard containers.
|
As long as you don't count string.
| Quote: |
struct S {
deque<S> d;
list<S> l;
map<S, S> m;
set<S> s;
vector<S> v;
|
basic_string<S> str; // "error: invalid application of "
// 'sizeof' to an incomplete type"
Jonathan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Balog Pal Guest
|
Posted: Sun Feb 22, 2004 11:02 am Post subject: Re: deque C2027 error |
|
|
"Nariman" <nariman_sg (AT) yahoo (DOT) com> wrote
| Quote: | typedef deque<T> D;
class T
{
int i, j;
D c;
}
When compiled under .NET, I get the following error:
error C2027: use of undefined type 'T' ....
|
Yep, you're out of luck with that one.
| Quote: | I know the problem is that instantiating deque requires a complete
type and
class T isn't yet a complete type. How can I modify the code so that
it compiles under .NET?
|
Use D* (or better a fit smart ptr) instead of D, and creat the instance in
ctor.
I have a similar problems with having a CList of the type as a member --
that would be completely reasonable, but I can't make it compile either,
Paul
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Sun Feb 22, 2004 5:30 pm Post subject: Re: deque C2027 error |
|
|
Jonathan Turkanis wrote in news:c192f0$1fpg54$1 (AT) ID-216073 (DOT) news.uni-
berlin.de:
| Quote: |
"John Potter" <jpotter (AT) falcon (DOT) lhup.edu> wrote in message:
The fundamental problem is why the standard makes it undefined when
compilers like gcc handle all standard containers.
As long as you don't count string.
|
This clause describes components for manipulating sequences of
“characters,” where characters may be of any POD (3.9) type. In
this clause such types are called char-like types, and objects of
char-like types are called char-like objects or simply “characters.”
POD structs can only have POD members and std::basic_string<> isn't
a POD.
| Quote: |
struct S {
deque<S> d;
list<S> l;
map<S, S> m;
set<S> s;
vector<S> v;
basic_string<S> str; // "error: invalid application of "
// 'sizeof' to an incomplete type"
};
|
Rob.
--
http://www.victim-prime.dsl.pipex.com/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Mon Feb 23, 2004 11:27 am Post subject: Re: deque C2027 error |
|
|
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message
| Quote: | The fundamental problem is why the standard makes it undefined
when
compilers like gcc handle all standard containers.
As long as you don't count string.
POD structs can only have POD members and std::basic_string<> isn't
a POD.
|
Whoop! You're right.
Anyway, if the rules were to be weakened, it would be necessary to
specify for each template whether it could be instantiated for an
incomplete type. This might be okay, it would be another indirect
restriction on possible implementations, like complexity
requiremenets.
But it might also rule out implementations which might otherwise be
reasonable in certain contexts. For instance, Thomas Mang suggested
recently that a vector might statically allocate a small buffer for
storing a certain number of instances of its value type, to avoid heap
allocation for small vectors. I'm not sure if this implementation is
allowed, but it would seem to be ruled out by the proposed change.
Jonathan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| 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
|
|