473,756 Members | 5,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::deque< class > member variable within class - A little help please

He everyone,

I am just getting started with .NET and I am having a porting problem.
I get and error in code that lookssomething like this (really stripped down
but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own type.

Code like this use to compile just fine under VC6.

Under VS.NET the compiler tells me that 'dt' is not defined when it trys to
compile this. I get the following...

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\includ e\deque(59) :
error C2027: use of undefined type
'dt'c:\dan\cwor k\transolv\tran solvDoc.cpp(28) : see declaration of 'dt'
c:\dan\cwork\tr ansolv\transolv Doc.cpp(29) : see reference to class template
instantiation 'std::deque<_Ty >' being compiled
with
[
_Ty=dt
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\includ e\deque(60) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\tr ansolv\transolv Doc.cpp(28) : see declaration of 'dt'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\includ e\deque(61) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\tr ansolv\transolv Doc.cpp(28) : see declaration of 'dt'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\includ e\deque(62) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\tr ansolv\transolv Doc.cpp(28) : see declaration of 'dt'
It looks like the "updated" STL needs to know the size of the 'dt' class
when it trys to compile the code but since it is inside the class it hasn't
figured it's size out yet.
It looks like it is also assigning the type 'dt' to a varaible inside the
deque template class.

Is there work-around someone knows about? I use this design feature in a
lot of code I developed in VC6 and it represents a major re-write if I can't
figure away around this.

Thanks in advance
Dan Trowbridge


Nov 16 '05 #1
7 3479
Dan Trowbridge wrote:
He everyone,

I am just getting started with .NET and I am having a porting problem.
I get and error in code that lookssomething like this (really
stripped down but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own
type.
This is not legal C++ - it's illegal to instantiate any standard library
class on an incomplete type.

Is there work-around someone knows about? I use this design feature
in a lot of code I developed in VC6 and it represents a major
re-write if I can't figure away around this.


Better get busy re-writing.

-cd
Nov 16 '05 #2
Bummer - but thanks for the info.

Dan
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:u1******** ********@TK2MSF TNGP11.phx.gbl. ..
Dan Trowbridge wrote:
He everyone,

I am just getting started with .NET and I am having a porting problem.
I get and error in code that lookssomething like this (really
stripped down but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own
type.


This is not legal C++ - it's illegal to instantiate any standard library
class on an incomplete type.

Is there work-around someone knows about? I use this design feature
in a lot of code I developed in VC6 and it represents a major
re-write if I can't figure away around this.


Better get busy re-writing.

-cd

Nov 16 '05 #3
Carl,

Do you have a suggestion of a way to obtain the same functionallity this
construct affords me.

I use this many places in quite a few codes.

An example is a matrix class where the "current" or "this" matrix is the
matrix sum of all the matrices in the deque, each is in-turn the sum of all
the matrices in its deque and so on. If the deque is emplty then data
stored in the matrix class is used to define the "this" matrix. In the case
I am describing I am using the BOOST UBLAS library to actually store the
matrices and do the matrix multiplication.

Again, this is just one example. I do this type of things many places, eg.

-Storing temperature dependant material properties where the values at the
root class object contains values interpolated for a given temperature
between the appropriate material properties in listed in the deque for
specific termperatures.

-Parsing files where each "card" (I'm starting to show my age) class
contains a deque of other "cards" in the file based on keyword, subkeywords,
etc. Feed the head of the class "tree" the heiarchial keywords and it
parses and sorts an appropraitly formatted file.

You get the idea. All these and more have been working fine for years now.

Any design ideas would be appreciated. Right now my boss is not happy that
all the code I have written using this flawed design is now broken so I
would like to figure out a good fix fast.

Thanks for your response
Dan

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:u1******** ********@TK2MSF TNGP11.phx.gbl. ..
Dan Trowbridge wrote:
He everyone,

I am just getting started with .NET and I am having a porting problem.
I get and error in code that lookssomething like this (really
stripped down but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own
type.


This is not legal C++ - it's illegal to instantiate any standard library
class on an incomplete type.

Is there work-around someone knows about? I use this design feature
in a lot of code I developed in VC6 and it represents a major
re-write if I can't figure away around this.


Better get busy re-writing.

-cd

Nov 16 '05 #4
Dan -

Normally the approach would be to store pointers instead of class instances.
You might try replacing std::deque<Foo> with
std::deque<boos t::shared_ptr<F oo> >. That way all of the memory management
will be taken care of for you (as it is with the non-portable solution
you're using now). The resulting code will likely be more efficient too,
since your Foo's won't have to be copied when the deque needs to move
elements around (of course, if you never do any inserts/deletes to the
middle of the deque, they're not being copied anyway).

See www.boost.org if you're not familiar with Boost. Boost 1.30.2 works
very well with VC7.1.

-cd
Dan Trowbridge wrote:
Carl,

Do you have a suggestion of a way to obtain the same functionallity
this construct affords me.

I use this many places in quite a few codes.

An example is a matrix class where the "current" or "this" matrix is
the matrix sum of all the matrices in the deque, each is in-turn the
sum of all the matrices in its deque and so on. If the deque is
emplty then data stored in the matrix class is used to define the
"this" matrix. In the case I am describing I am using the BOOST
UBLAS library to actually store the matrices and do the matrix
multiplication.

Again, this is just one example. I do this type of things many
places, eg.

-Storing temperature dependant material properties where the values
at the root class object contains values interpolated for a given
temperature between the appropriate material properties in listed in
the deque for specific termperatures.

-Parsing files where each "card" (I'm starting to show my age) class
contains a deque of other "cards" in the file based on keyword,
subkeywords, etc. Feed the head of the class "tree" the heiarchial
keywords and it parses and sorts an appropraitly formatted file.

You get the idea. All these and more have been working fine for
years now.

Any design ideas would be appreciated. Right now my boss is not
happy that all the code I have written using this flawed design is
now broken so I would like to figure out a good fix fast.

Thanks for your response
Dan

"Carl Daniel [VC++ MVP]"
<cp************ *************** **@mvps.org.nos pam> wrote in message
news:u1******** ********@TK2MSF TNGP11.phx.gbl. ..
Dan Trowbridge wrote:
He everyone,

I am just getting started with .NET and I am having a porting
problem. I get and error in code that lookssomething like this
(really
stripped down but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own
type.


This is not legal C++ - it's illegal to instantiate any standard
library class on an incomplete type.

Is there work-around someone knows about? I use this design
feature in a lot of code I developed in VC6 and it represents a
major
re-write if I can't figure away around this.


Better get busy re-writing.

-cd

Nov 16 '05 #5
Carl,

Well thanks for the help. Using pointers is the way I use to do it but, as
you know by your suggestion about using boost::shared_p ointer, there is
quite a bit of overhead. To force you to use pointers seems to go against
the idea behind some of the best things about C++, e.g. inheritance, virtual
functions, abstraction, the whole generic programming thought. It seems
like an inconsistency.

It is a shame that what I was doing doesn't work now (or really shouldn't
have worked all along). I wonder why the standard committee disallowed
(never allowed) it. It obviously works (or can work) - I have used it for a
long time and the VS C++ 6.0 compiler didn't complain about it. I guess
ignorance is NOT bliss. Oh well, I will leave that to smarter people than
me. Enough lamenting - time to get coding.

Thanks again for your prompt and helpful response.
Dan

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:ew******** ******@TK2MSFTN GP10.phx.gbl...
Dan -

Normally the approach would be to store pointers instead of class instances. You might try replacing std::deque<Foo> with
std::deque<boos t::shared_ptr<F oo> >. That way all of the memory management will be taken care of for you (as it is with the non-portable solution
you're using now). The resulting code will likely be more efficient too,
since your Foo's won't have to be copied when the deque needs to move
elements around (of course, if you never do any inserts/deletes to the
middle of the deque, they're not being copied anyway).

See www.boost.org if you're not familiar with Boost. Boost 1.30.2 works
very well with VC7.1.

-cd
Dan Trowbridge wrote:
Carl,

Do you have a suggestion of a way to obtain the same functionallity
this construct affords me.

I use this many places in quite a few codes.

An example is a matrix class where the "current" or "this" matrix is
the matrix sum of all the matrices in the deque, each is in-turn the
sum of all the matrices in its deque and so on. If the deque is
emplty then data stored in the matrix class is used to define the
"this" matrix. In the case I am describing I am using the BOOST
UBLAS library to actually store the matrices and do the matrix
multiplication.

Again, this is just one example. I do this type of things many
places, eg.

-Storing temperature dependant material properties where the values
at the root class object contains values interpolated for a given
temperature between the appropriate material properties in listed in
the deque for specific termperatures.

-Parsing files where each "card" (I'm starting to show my age) class
contains a deque of other "cards" in the file based on keyword,
subkeywords, etc. Feed the head of the class "tree" the heiarchial
keywords and it parses and sorts an appropraitly formatted file.

You get the idea. All these and more have been working fine for
years now.

Any design ideas would be appreciated. Right now my boss is not
happy that all the code I have written using this flawed design is
now broken so I would like to figure out a good fix fast.

Thanks for your response
Dan

"Carl Daniel [VC++ MVP]"
<cp************ *************** **@mvps.org.nos pam> wrote in message
news:u1******** ********@TK2MSF TNGP11.phx.gbl. ..
Dan Trowbridge wrote:
He everyone,

I am just getting started with .NET and I am having a porting
problem. I get and error in code that lookssomething like this
(really
stripped down but you get the idea)...

class dt
{
std::deque< class dt > dtdq;
};

That is a class that contains a deque of class objects of it's own
type.

This is not legal C++ - it's illegal to instantiate any standard
library class on an incomplete type.
Is there work-around someone knows about? I use this design
feature in a lot of code I developed in VC6 and it represents a
major
re-write if I can't figure away around this.

Better get busy re-writing.

-cd


Nov 16 '05 #6
"Dan Trowbridge" <da************ @hotmail.com> wrote in message
news:S8******** *********@fe1.c olumbus.rr.com. ..

Well thanks for the help. Using pointers is the way I use to do it but, as
you know by your suggestion about using boost::shared_p ointer, there is
quite a bit of overhead.


The only overhead of a boost::shared_p ointer versus a standard pointer should
be when you are creating/copying/destroying them, which should not happen
often in your deque.

Of course, both shared pointers and standard pointers will put you one level
of indirection further from your data. That will involve some overhead, but
I'd hesitate to call it "quite a bit", unless the type being pointed to is
pretty simple.

Ken
Nov 16 '05 #7
Dan Trowbridge <da************ @hotmail.com> wrote:
Carl,

Well thanks for the help. Using pointers is the way I use to do it but, as
you know by your suggestion about using boost::shared_p ointer, there is
quite a bit of overhead. To force you to use pointers seems to go against
the idea behind some of the best things about C++, e.g. inheritance, virtual
functions, abstraction, the whole generic programming thought. It seems
like an inconsistency.
I don't see how to get rid of the overhead
for 'new'/'delete'. However, you might be
able to leave the code that uses these
containers unchanged, if you crate a kind
of "reference class". Something like this:

template< typename T >
class reference {
public:
reference(T* p) : ptr_(p) {assert(ptr_);}
operator T&() {return *ptr_);
operator const T&() const {return *ptr_);
private:
T* ptr_;
};
It is a shame that what I was doing doesn't work now (or really shouldn't
have worked all along). I wonder why the standard committee disallowed
(never allowed) it. It obviously works (or can work) - I have used it for a
long time and the VS C++ 6.0 compiler didn't complain about it. I guess
ignorance is NOT bliss. Oh well, I will leave that to smarter people than
me. Enough lamenting - time to get coding.
I wouldn't know the details behind that
restriction. But you should consider that
VC6 might only have gotten away with this
because it is so horribly broken when it
comes to templates. It might just not have
implemented some feature (correctly),
which wouldn't work with this code.
Thanks again for your prompt and helpful response.
Dan
[...]


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1528
by: Dan Trowbridge | last post by:
He everyone, I just getting started with .NET and I am having a porting problem. I get and error in code that lookes like this (really stripped down but you get the idea)... class dt { std::deque< class dt > dtdq; };
8
2968
by: Gernot Frisch | last post by:
std::deque<intd; d.push_front(13); int* p13 = &d.begin(); d.push_front(1); d.push_back(2); Can I be safe, that p13 points to 13? I mean, unless I erase the 13, of course.
7
7232
by: DevNull | last post by:
Hello everyone, I decided to pick c++ back up after not really having used it much in 10 years. Just as a point of refference, there was no standard C++ last time I used regularly. Anyways coming back, I've fallen in love with all the improvements in the language such as the STL. Congrats to anyone who worked on it, you did an excellent job.
2
6442
by: bb | last post by:
Hi, Is there any specific reason why std::deque's pop_front & pop_back does not return the removed object? It could return the removed object by value (possibly atomically?) Cheers.
12
2648
by: arnuld | last post by:
It works fine. any advice on making it better or if I can improve my C++ coding skills: /* C++ Primer - 4/e * * Chapter 9 - Sequential Containers * exercise 9.18 - STATEMENT * Write a program to copy elements from a list of "ints" * to 2 "deques". The list elements that are even should go into one deque * and even elements should go into 2nd deque.
3
3047
by: Yuan | last post by:
hi, I do not know if this worth a cent. we know vector<boolis bad and we should use deque<bool>. However, this guy gives me some trouble, (pls correct me if I am wrong). In vector, the mem is guaranteed to be a continous block. however, for deque, NO!! So when we try to get an array out of a vector, we just set the pointer to be the &vec, done.
29
9131
by: NvrBst | last post by:
I've read a bit online seeing that two writes are not safe, which I understand, but would 1 thread push()'ing and 1 thread pop()'ing be thread-safe? Basically my situation is the follows: --Thread 1-- 1. Reads TCPIP Buffer 2. Adds Buffer to Queue (q.size() to check queue isn't full, and q.push_back(...)) 3. Signals Reading Thread Event & Goes Back to Wait for More Messages on TCPIP
2
2412
by: subramanian100in | last post by:
In ISO/IEC 14882:2003 document, in the section '23.2.1.3 deque modifiers', the following is mentioned: iterator insert(iterator position, const T& x); void insert(iterator position, size_type n, const T& x); template <class InputIterator> void insert(iterator position, InputIterator first, InputIterator last);
0
9462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.