news@bbn.COM (News system owner ID) (07/19/89)
mind: From: gww@bbn.com (George Williams) Path: bbn.com!gww 1) The report says that the const qualifier is treated rather like a #define in C++ in that a declaration const int i=3; with external scope does not define an external variable in C++. After fiddling a little with my C++ translator here (Designer C++) I noticed that this statement is true for ints, shorts, longs, chars, unsigneds, etc. but not for doubles, floats, enums, pointers, classes, arrays. Is this discrepency fixed in version 2? (and how on earth is the compiler supposed to deal with a constant class initialized by an external constructor?) What is supposed to happen if one takes the address of what would be in ANSI c an external constant integer? (or is that illegal) 2) another question about constants, suppose I have a class class number { /* ... */ public: number(int); operator+(number&); operator+=(number&); }; const number zero(0); foo() { number x; zero+x; zero += x; } Now since a `this' argument has type pointer to number it should not accept a constant number. However if we say this constant objects are useless. On the other hand if we say the type of this is pointer to const number then we can't write a += operator. How should C++ handle constant objects? 3) The Report indicates that foo() { /* ... */ goto L1; /* ... */ { String x(10); L1: } } is illegal because the constructor for x never gets called. Is foo() { /* ... */ goto L1; /* ... */ String x(10); L1: } also illegal (again the constructor for x does not get called) Assume there is a destructor for String, then is foo() { /* ... */ { String x(10); goto L1; } L1: } illegal? (since the destructor for x doesn't get called) or does the goto force all destructors to happen? 4) Consider for ( i=0 ; i<10; ++i ) String j(10); To my understanding this is valid C++, what is the scope of j? If its scope lasts from here to the end of the block then doesn't its constructor get called 10 times and its destructor only once? On the other hand there is nothing in the syntax to indicate that j has a scope limitted to the while. 5) The report mentions that in version 2 classes define a local scope in that enums declared inside the class are only available inside the class (and its members). Does this extend to classes defined inside another class? (if not why not) If it does extend to classes what happens to all the classes which do forward declarations of other classes, as: class mumble { friend class fumble; /* where this is the first time we've */ /* seen fumble in this file */ struct spatterdock *flower; /* where this is the first instance */ /* of spatterdoc */ }; 6) I have noticed that in Designer C++ a constructor is always public, even if it isdeclared in a private part of the class (and the same is true of the destructor)? I can imagine cases where protected constructors might be useful, I have a far harder time seeing any use for private ones, and I can't see any use at all for a private/protected destructor. Should it be legal to have private constructors/destructors, and what does it mean? If not shouldn't the compiler make some indication that it is changing the protection on these functions?