Code as follows:
#include <iostream> // std::cout
#include <string> // std::string
#include <memory> // std::auto_ptr
class Window
{
public:
typedef std::auto_ptr<W indow> AutoPtr;
virtual ~Window() {}
static AutoPtr newObject() { return AutoPtr( new Window ); }
}; // class Window
class Button: public Window
{
public:
typedef std::auto_ptr<B utton> AutoPtr;
static AutoPtr newObject() { return AutoPtr( new Button ); }
}; // class Button
int main()
{
Window::AutoPtr pWindow( Window::newObje ct() );
Window::AutoPtr pButton( Button::newObje ct() ); // <--
std::cout << "Onky donk" << std::endl;
}
The line marked with an arrow attempts to convert a Button::AutoPtr to
a Window::AutoPtr .
I had the impression that this should work fine, but compiled with VC
7.1 it just enters an infinite recursion in 'auto_ptr<Butto n>::operator
auto_ptr_ref<Wi ndow>', giving a stack overflow in very short time; is
this a bug in the code above, in the standard library implementation, or
in the compiler (I know there are subtle issues with temporaries)?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? 3 1411
On Sun, 20 Jun 2004 01:20:47 GMT in comp.lang.c++, al***@start.no (Alf
P. Steinbach) wrote, I had the impression that this should work fine, but compiled with VC 7.1 it just enters an infinite recursion in 'auto_ptr<Butto n>::operator auto_ptr_ref<W indow>', giving a stack overflow in very short time;
Beats me. For what it's worth, compiles without error using Digital
Mars C++ and STLPORT (free download from http://www.digitalmars.com)
and prints "Onky donk".
"Alf P. Steinbach" <al***@start.no > wrote in message
news:40******** *********@news. individual.net. .. Code as follows:
#include <iostream> // std::cout #include <string> // std::string #include <memory> // std::auto_ptr
class Window { public: typedef std::auto_ptr<W indow> AutoPtr; virtual ~Window() {} static AutoPtr newObject() { return AutoPtr( new Window ); } }; // class Window
class Button: public Window { public: typedef std::auto_ptr<B utton> AutoPtr; static AutoPtr newObject() { return AutoPtr( new Button ); } }; // class Button
int main() { Window::AutoPtr pWindow( Window::newObje ct() ); Window::AutoPtr pButton( Button::newObje ct() ); // <-- std::cout << "Onky donk" << std::endl; }
The line marked with an arrow attempts to convert a Button::AutoPtr to a Window::AutoPtr .
I had the impression that this should work fine, but compiled with VC 7.1 it just enters an infinite recursion in 'auto_ptr<Butto n>::operator auto_ptr_ref<Wi ndow>', giving a stack overflow in very short time; is this a bug in the code above, in the standard library implementation, or in the compiler (I know there are subtle issues with temporaries)?
It's a bug in the library. For what it's worth vc7.1 will warn you (unless
you turn off warnings:-):
warning C4717: 'std::auto_ptr< Button>::operat or<Window>
std::auto_ptr_r ef<Window>' :recursive on all control paths, function will
cause runtime stack overflow
What's even worse is that vc7.1 will allow to convert to totally unrelated
types with exactly the same warning - no error!
std:auto_ptr of Metrowerks CodeWarrior 9.2 works fine with this example.
Conrad Weyns -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
David Harmon <so****@netcom. com.invalid> wrote in message news:<40******* ********@news.w est.earthlink.n et>... On Sun, 20 Jun 2004 01:20:47 GMT in comp.lang.c++, al***@start.no (Alf P. Steinbach) wrote,I had the impression that this should work fine, but compiled with VC 7.1 it just enters an infinite recursion in 'auto_ptr<Butto n>::operator auto_ptr_ref<W indow>', giving a stack overflow in very short time;
Beats me. For what it's worth, compiles without error using Digital Mars C++ and STLPORT (free download from http://www.digitalmars.com) and prints "Onky donk".
I can't even compile the code..my compiler gives following error:
**
cxx: Error: /usr/include/cxx/memory, line 877: member
"std::auto_ptr< Button>::owner" is inaccessible
detected during instantiation of
"std::auto_ptr< Window>::auto_p tr(const std::auto_ptr<B utton> &)" at
line 23 of "template_Test. cpp"
: owner(a.owner),
the_p((_RWSTD_C ONST_CAST(auto_ ptr<Y>&,a)).rel ease())
----------------^
1 error detected in the compilation of "template_Test. cpp".
**
I am compiling it on Digital UNIX. Can it be some Library Issue?
regds,
AD This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Fisher |
last post by:
I'm seeing an error when I try to run/debug a web
service. Although it doesn't happen every time, it does
occur more than half of the times I hit F5. It appears
to be returned by the the JIT compiler as the page is
requested by the browser. The result is that
the "compiler failed with error code 2000". I have
tested the same code on another workstation with VS.NET
and it works fine EVERY time. I'm convinced it's not the
code and I...
|
by: Steven T. Hatton |
last post by:
Some people have suggested the desire for code completion and refined
edit-time error detection are an indication of incompetence on the part of
the programmer who wants such features. Unfortunately these ad hominem
rhetorts are frequently introduced into purely technical discussions on the
feasibility of supporting such functionality in C++. That usually serves
to divert the discussion from the technical subject to a discussion of the...
|
by: Bryan Olson |
last post by:
The current Python standard library provides two cryptographic
hash functions: MD5 and SHA-1 . The authors of MD5 originally
stated:
It is conjectured that it is computationally infeasible to
produce two messages having the same message digest.
That conjecture is false, as demonstrated by Wang, Feng, Lai and
Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short-
cut solution for finding collisions in SHA-1 . Their result
|
by: Karthik |
last post by:
Hi,
I have a library libXpm.so.4.11 and a header file xpm.h. Now I have a
c code which uses a function in this library. I am not sure how to
compile my code with this library. I include the header file in the
usual way in the C code. I have the library and the header file in the
same directory as the c file. How should I compile this code in order
to make the functions present in the library visible to the compiler.
I am not all that...
|
by: junky_fellow |
last post by:
On what basis it is decided that a particular funtion should
be a part of Standard C library ?
Do I get these standard C libraries along with the C compiler ?
Or I can use the c complier from one vendor and the standard
C libraries from the different vendor ?
Also, the C standard (N869), page 164, refers to "standard
headers". Do I get these standard headers along with the
C compiler ?
| |
by: Mike |
last post by:
Is it still true that the managed C++ compiler will produce much better
opimizations than the C# compiler, or have some of the more
global/aggressive opimizations been rolled into the 2005 compiler?
Are simple common sub-expressions and loop invariants optimized out in the
current optimizer?
thanks,
m
|
by: Julian |
last post by:
I get the following error when i try to link a fortran library to a c++ code
in .NET 2005.
LINK : fatal error LNK1104: cannot open file 'libc.lib'
the code was working fine when built using .NET2003.
also, when I do not try to link the fortran library (just to see if that was
the cause), it builds the exe without any problems.
i don't even know how to begin addressing this problem...any help would be
|
by: Eigenvector |
last post by:
I apologize if this is a trivial question, but it's always made me wonder
when I have to compile my code.
There are some #includes that you don't really need to reference in your
library and header references in the compilation string.
For instance the standard hello.c
#include <stdio.h>
int main()
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first
set of examples, after decoding the HTML FORM contents, merely
verifies the text within a field to make sure it is a valid
representation of an integer, without any junk thrown in, i.e. it
must satisfy the regular expression: ^ *?+ *$
If the...
|
by: somenath |
last post by:
Hi All,
I was going through one of the exercise of one C tutorial .
In that they have given one small code and asked about the output.
#include <stdio.h>
int main(void)
{
int x = 0xFFFFFFF0;
signed char y;
|
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...
| |
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,...
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |