473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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\include\deque(59) :
error C2027: use of undefined type
'dt'c:\dan\cwork\transolv\transolvDoc.cpp(28) : see declaration of 'dt'
c:\dan\cwork\transolv\transolvDoc.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\include\deque(60) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\transolv\transolvDoc.cpp(28) : see declaration of 'dt'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\deque(61) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\transolv\transolvDoc.cpp(28) : see declaration of 'dt'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\deque(62) :
error C2027: use of undefined type 'dt'
c:\dan\cwork\transolv\transolvDoc.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 3451
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.nospam >
wrote in message news:u1****************@TK2MSFTNGP11.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.nospam >
wrote in message news:u1****************@TK2MSFTNGP11.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<boost::shared_ptr<Foo> >. 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.nospam > wrote in message
news:u1****************@TK2MSFTNGP11.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_pointer, 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.nospam >
wrote in message news:ew**************@TK2MSFTNGP10.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<boost::shared_ptr<Foo> >. 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.nospam > wrote in message
news:u1****************@TK2MSFTNGP11.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.columbus.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_pointer, there is
quite a bit of overhead.


The only overhead of a boost::shared_pointer 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_pointer, 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
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 {...
8
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
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...
2
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
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 * ...
3
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...
29
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: ...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.