Subj : Re: works only outside class To : borland.public.cpp.borlandcpp From : maeder@glue.ch (Thomas Maeder [TeamB]) Date : Wed Dec 24 2003 02:50 pm Gerhard Wolfstieg writes: > Which kind of reasons are conceivable in the following case? There is not much difference in the code you show. I'm just giving an educated guess here. If I guess wrong, I'm afraid you'll have to reduce your program to the absolutely minimal size that still causes the behavior you see (<50 lines) and post the result. > This code is running fine: >>> > int > main( int, char *[] ) > { > ... > term_t ref = PL_new_term_ref(); This initializes ref with the return value of PL_new_term_ref(). In principle, the term_t copy constructor is used for this, but it could also be be optimized away. > if( !PL_chars_to_term( "x( A, 2 )", ref ) ) > throw RC_Syntaxfehler; > ... > } > << > The next does not work (it seems to loop in a second thread): >>> > struct gwTerm > { term_t ref; > > gwTerm( char const * ); > }; > > gwTerm::gwTerm( char const *text ) Now ref is first default_constructed, since you don't explicitly initialize it in the member-initializer list. > { ref = PL_new_term_ref(); Then you copy-assign the return value of PL_new_term_ref() to ref, using term_t's copy-assignment operator. If term_t's copy constructor and copy-assignment operator are correctly written (or generated), the second version should only be less efficient than the first. To cause ref to be initialized in the second version like it is initialized in the first version, change the constructor implementation to gwTerm::gwTerm( char const *text ) : ref(PL_new_term_ref()) { if( !PL_chars_to_term( text, ref ) ) throw RC_Syntaxfehler; } .