delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/01/07/23:20:34

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
From: Rolf Campbell <Endlisnis AT mailc DOT net>
Subject: Re: auto_ptr gcc version 3.3.1 (cygming special) problem
Date: Wed, 07 Jan 2004 23:20:09 -0500
Lines: 86
Message-ID: <btilpq$g0i$1@sea.gmane.org>
References: <3FFCD90C DOT 6000905 AT terra DOT com DOT br>
Mime-Version: 1.0
X-Complaints-To: usenet AT sea DOT gmane DOT org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4
In-Reply-To: <3FFCD90C.6000905@terra.com.br>

#1)  This is not a cygwin issue, so it's off-topic here.
#2)  This is not even really a gcc issue, it's a C++ issue.
#3)  The problem is that you are trying to use static_cast too much.  It 
should only be used for built-in types (int, float, various pointers).

The older gcc seemed to allow incorrect use of static_cast, the new one 
requires you to use it right.

Just remove the static casts, and away we are:

int main(int argc, char *argv[])
{
   A a(1);
   auto_ptr<B> b = auto_ptr<B>(a.getB());
   A a2(2);
   auto_ptr<B> b2 = auto_ptr<B>(a2.getB());
   cin.get();
   return 0;
}

Or even:

int main(int argc, char *argv[])
{
   A a(1);
   auto_ptr<B> b(a.getB());
   A a2(2);
   auto_ptr<B> b2(a2.getB());
   cin.get();
   return 0;
}



Marcelo Rezende Módolo wrote:
> Hi,
> I am not shure that this is a error , but it is very strange...
> 
> //autoPtr.cpp
> #include <iostream>
> #include <memory>
> using namespace std;
> 
> class B  {
> public:
>    B(int cid) : cid_(cid) { cout << "B(" << cid_ << ")\n"; }
>    ~B() { cout << "~B(" << cid_ << ")\n"; }
> private:
>    int cid_;          };
> 
> class A  {
> public:
>    A(int cid) : cid_(cid) { cout << "A(" << cid_ << ")\n"; }
>    ~A() { cout << "~A(" << cid_ << ")\n"; }     B* getB() { return new 
> B(cid_); }
> private:
>    int cid_;  };
> 
> int main(int argc, char *argv[])
> {
>    A a(1);
>    auto_ptr<B> b = static_cast< auto_ptr<B> >(a.getB());
>    A a2(2);
>    auto_ptr<B> b2 = static_cast< auto_ptr<B> >(a2.getB());
>    cin.get();
>  return 0;
> }
> 
> If I compile this file with gcc version 3.2.3 (mingw special 20030504-1) 
> no errors ocur (g++ -o autoPtr autoPtr.cpp).
> But if I try to compile using gcc version 3.3.1 (cygming special), with 
> the same command line (g++ -o autoPtr autoPtr.cpp),
> this errors ocur:
> autoPtr.cpp: In function `int main(int, char**)':
> autoPtr.cpp:26: error: invalid static_cast from type `B*' to type `
>   std::auto_ptr<B>'
> autoPtr.cpp:29: error: invalid static_cast from type `B*' to type `
>   std::auto_ptr<B>'
> 
> what is the problem??
> 
> thanks,
> marcelo
> 
> 
> 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019