Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++]warningc4355

    ciao.
    ho il seguente warning:
    c:\IFCXML\ifc\ifc\nillable-type.hxx(137): warning C4355: 'this' : used in base member initializer list
    su questo costruttore:
    codice:
     complex_nillable_type (const complex_nillable_type& x,
                             xml_schema::flags f = 0,
                             xml_schema::container* c = 0)
          : B (x, f, c), nil_ (x.nil_),
            ref_ (xml_schema::idref (""), 0, this)
             {
    	  
    	  ref_ = x.ref_;
      }
    e non riesco a capire cosa vuole dire mi date una mano?

    'this' : used in base member initializer list

    The this pointer is valid only within nonstatic member functions. It cannot be used in the initializer list for a base class.

    The base-class constructors and class member constructors are called before this constructor. In effect, you've passed a pointer to an unconstructed object to another constructor. If those other constructors access any members or call member functions on this, the result will be undefined. You should using the this pointer until all construction has completed.

    This is a level-1 warning under Microsoft extensions (/Ze) and a level-4 warning otherwise.

    The following sample generates C4355:

  2. #2
    Semplicemente che non puoi usare this nella sua lista di inizializzazione, ne (solo in alcuni casi) nel suo costruttore.

    Quando usi this nel costruttore, l'oggetto che referenzi con this non è ancora costruito del tutto.
    E' solo un warning infatti, perchè la memoria per l'oggetto è allocata, ma finisci in un "undefined behavoir" perchè non si sa se l'oggetto è costruito del tutto.
    Dipende dalla velocità con cui la tua CPU e RAM allocano l'oggetto.

    Non inizializzare ref nella lista d'inizializzazione, fallo nel costruttore, però attento. Se ref nel suo costruttore usa un metodo di this non sai se il tuo programma crasherà o meno perchè come detto l'oggetto può anche non essere allocato del tutto.
    lolide
    Java Programmer

    Informati

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.