[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [C++] new class, fail. Ønskes: NULL pointer



On Tue, 13 Jan 2004 12:48:12 +0100
Hans Schou <sslug@sslug> wrote:

> 
> Hej
> 
> Æv, så fik jeg en segmentation fault.
> 
> Jeg opretter et object (class). Under init finder jeg ud af at den går 
> ikke, og så vil jeg gerne have returneret NULL.
> 
> 	foo = new bar();
> 
> I ovenstående skal foo så være NULL, hvis bar() fejler.
> 
> Kan man det? Eller griber jeg det forkert an?


Du kunne gøre noget ala:

   class myClass {
      public:
         myClass() { // Gør noget... sæt _stat }
         bool isNull() { return _stat; }
         bool operator () () { return _stat; }

      private:
         bool _stat;
   };


Så kan du senere bruge:

   myClass *foo = new myClass();
   if( !(*foo)() )   // bruger operator ()
      ...
   
   if( !foo->isNull() )
      ...

   delete foo;


> I virkeligheden er det en hægtet liste,
> så det er nemt at håndtere senere.
> 	link.additem(new bar());


Hvorfor bruger du ikke STL ?


(John =;-)


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *