HDTenEightyP/NetNews huggingface dataset:
Organization: Queen's University at Kingston
Date: Tue, 10 Nov 1992 10:41:03 EDT
From: <0407658@QUCDN.QueensU.CA>
Newsgroups: comp.lang.c++
Subject: Constructor doesn't use overloading??

Hello C++ Experts
I am learning C++ (I'm up to page 320 of LaFore!) and I am surprised by a
fact about constructors and overloaded assignment operators.  Am I
interpreting this correctly?  I have a class called time which has a 3
argument constructor with defaults:

      time(int hh=0, int mm=0, int ss=0) ; // constructor - defined later

I also have an overloaded assignment operator which does a bit of
housekeeping as shown below complete with debugging code:

      time & operator = (const time t)
      // assigns a time t to self AND converts it to proper format
      {   cout << "\nI'm in = and t.second is " << t.second ; // debugging
           second = t.second % 60 ;
           cout << "second is " << second ;                   // debugging
           minute = (int(t.second / 60) + t.minute) % 60 ;
           hour = (int(t.minute / 60 ) + t.hour ) % 12 ;
           return * this ;
      }
My surprise is that in main(), if I have:

  void main()
  {    time t1(7, 5, 125) ;
       time t2(6,2) ;
       time t3 = t1 ;
       ...
the overloaded = is not called;  whereas if I change it to
void main()
{    time t1(7, 5, 125) ;
     time t2(6,2) ;
     time t3 ;
     t3 = t1 ;
then the = is called as expected.

Could someone please enlighten this determined beginner as to why this
is so and why its a good thing.  I truly expected the overloaded = to be
called in both cases.  Thanks for your time, I really do appreciate it.

Don
From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
Newsgroups: comp.lang.c++
Subject: Re: Class scope and class declarations
Date: 7 Nov 92 16:39:16 GMT
Organization: University of Birmingham

In article <JEP.92Nov6155424@thneed.cs.duke.edu>, jep@cs.duke.edu (Jonathan E. Polito) writes:
> It is clear that:
> class X;
> 
> class Y {
> public:
> 	Y();
> private:
> 	class X* xptr;
> };
> 
> class X {
> public:
> 	int info;
> };
> 
> Y::Y() {
> 	X tmp;
> 	tmp.info = 1;
> }
> 
> will cause tmp to be defined as a class X (at file scope) object. What
> if the first class X; forward declaration is deleted though? Is the
> effect then that xptr in class Y is a pointer to a local class X that
> is never defined? This is one interpretation though I have seen a
> number of programs that rely on class X* to be a forward declaration
> to a class defined later at file scope.
It seems like only yesterday I answered this same question in comp.std.c++ -
hey hang on it *was* yesterday.

If you say `class X;' this is a forward declaration to a class defined later.
If you say `X *xptr;' this referres to a class X that has already been
declared (and must be in scope).

If you use the hybrid form `class X *xptr;' this will be compiled as
`X *xptr;' if there is a class X in scope otherwise it will be compiled as 
`class X; X *xptr'. (IMHO it is best to avoid the hybrid form.)

In C++ Ed.1 all classes had file scope so old software that relied on the
fact that there was no such thing as nested class scopes will not compile
correctly under a C++ Ed.2 compiler.

To fix old code it is usually suffient to insert forward declarations to
all classes at the top of the header. 
    \\   ( )  NO BULLSHIT! from BAM (Brian McCauley)          
 .  _\\__[oo  ============
.__/  \\ /\@
.  l___\\     E-mail: B.A.McCauley@bham.ac.uk
 # ll  l\\ 
###LL  LL\\
Newsgroups: comp.lang.c++
From: kkt@philabs.philips.com (Kim-Kiat Tan)
Subject: 32 bit compiler
Organization: Philips Laboratories, Briarcliff, New York
Date: Mon, 9 Nov 1992 15:31:33 GMT

        Anyone knows whether Borland has any plan to develop 32 bits compiler 
for dos ? If they have plan, I might develop my software with Borland c++ and
wait for their 32bit compiler, or else most likely I will go with Zortech or
Meta C. My feeling is that Borland has grown and is showing sign of the "big"
corporation, I requested information thro' the magazines' info. request card,
(I repeated, and have sent out 4 cards), never hear a single word from them.
My feeling is that they are saying that hey guy, we have enough customers 
without sending them brochures, why should I send you. (the first card was sent
4 months ago).
From: rjf@seiko.mpd.tandem.com (Russell Fleming)
Newsgroups: comp.lang.c++
Subject: Re: Operator Overload problem
Date: 6 Nov 92 21:33:31 GMT
Distribution: usa

In article <30001@nntp_server.ems.cdc.com>, jreed@ems.cdc.com (Jim Reed)
writes:
> Help!
> 
> I am having a problem getting my operator overload of the == 
> operator to work.  If I leave my code in one .C file it works.
> If I try to split it into a .C file and a .h file it doesn't.
> 
	... much deleted ...
>
> int EllLowerAddress::operator==(
>         EllLowerAddress address_1, EllLowerAddress address_2)
>
	.. much more deleted ...

Your problem is the manner in which you declared the operator== method. 
Since your class definition describes operator== as a friend function,
the correct way in which to declare it is:

int operator==(EllLowerAddress address_1, EllLowerAddress address_2) ...

If your class had instead declared the operator== method as a member
function, your instantiation of the function would have been correct.

=================================================================
Rusty Fleming, Software Consultant @ Tandem Computers Inc.
email: rjf@mpd.tandem.com            Austin, Texas
voice: (512) 244 - 8390              USA
Newsgroups: comp.lang.c++
From: schrod@iti.informatik.th-darmstadt.de (Joachim Schrod)
Subject: Re: Wanted: Red-Black Trees
Date: Thu, 12 Nov 1992 10:59:54 GMT
Organization: TU Darmstadt

In article <1992Nov11.103156.1@happy.colorado.edu>, srheintze@happy.colorado.edu writes:
> Does anyone have source to an implementation of Red-Black trees?
> I was going to type one in from a textbook (anyone know of a text book that has 
> Red-Black tree?) but if anyone has a softcopy it would save me the trouble.

Red-black trees are available in the LEDA class library.

Use archie to find a near ftp archive with LEDA.

European folks may fetch it from the reference host,
sbsvax.cs.uni-sb.de:pub/LEDA, or from the C++ archive at Darmstadt,
ftp.th-darmstadt.de:pub/programming/languages/C++/class-libraries/LEDA.

--
Joachim

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Joachim Schrod			Email: schrod@iti.informatik.th-darmstadt.de
Computer Science Department
Technical University of Darmstadt, Germany
Newsgroups: comp.lang.c++
From: walduck@mpr.ca (Andrew Walduck)
Subject: Re: Making qsort type-safe
Organization: MPR Teltech Ltd., Burnaby, B.C., Canada
Date: Fri, 6 Nov 92 20:27:32 GMT

In article <1992Nov5.160048.15113@bcrka451.bnr.ca> sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
>The library version of qsort on some machines behaves abysmally if many
>objects compare equal.  On more than one UNIX workstation I have seen qsort
>take more than 3/4 of an *hour* to sort a large list into two buckets,
>whereas an appropriately adjusted qsort takes 1/4 *second*.  (Yes I know 
>that qsort seems like a silly way to do what could be a single pass
>operation, but why should "sort" be applicable to only some kinds of sorts?)

It is precisely due to this behaviour that I prefer heapsort to quicksort...
Quicksort performance can rapidly approach O(N^2) as the list becomes closer
to being sorted!! (It depends how the pivot is chosen...)

Many people think of qsort as an O(nlogn) sort...it isn't. Its average
case is O(nlogn)...but its worst case is O(n^2) (the same as a bubble
sort!!) This behaviour, when combined with its stack requirements, is
why I prefer heap sort. In all cases, it performs as an O(nlogn) sort...
and it can be implemented in 2 success loops...(about 30 lines of code
or so...)

Andrew Walduck

-- 
Andrew Walduck, MPR Canada, walduck@mprgate.mpr.ca
-------------------------------------------------------------------------------
(I hope someone will flatter me by using this as a .sig quote...)
 -- Reid Kneeland
From: cooper@plains.NoDak.edu (Jeff Cooper)
Newsgroups: comp.lang.c++
Subject: how to initilize an array inside of a class??
Date: 12 Nov 92 03:46:14 GMT
Article-I.D.: ns1.BxL3t2.FKG
Organization: North Dakota Higher Education Computing Network

I have a bit of a problem that I can't really see an elegant solution
for and I hope someone can point me in the right direction.  I have
a class that looks something like this:

class Y : public X
{
    public:
        int some_ints[3000];
        Y();
        ...
};

Now what I'd need to do is initilize the array 'some_ints' with some
preset values...normally one would do it like:

int some_ints[3000] = { 1, 6, 34, 3, ... ,0 };

But my compiler complains about that, saying that I can't initialize
class members there.  The only other way I can think of doing it is
to do something like:

Y::Y()
{
    some_ints[0] = 1;
    some_ints[1] = 6;
    ...
    some_ints[2999] = 0;
}

Is this my only other option??  If it is, it's not really all that bad
as this code is being generated by another program, so I won't have to
type in 3000 entries like that, but I was hoping for a more elegant
solution...Would there be a performance hit doing it that way, I kinda
think so as the first one is done at compile time, while the other is
done at run-time, correct??

Any Ideas?


-- 
"Life is pain Highness, anyone	|  Jeff Cooper
who tells you different is	|  cooper@plains.nodak.edu
selling something."		|  NeXTMail: cooper%midkemia@plains.nodak.edu
    - The Dread Pirate Roberts	|  (701) 298-0893
Newsgroups: comp.lang.c++
From: donovan@well.sf.ca.us (Sean Donovan)
Subject: Re: Multiple Header Files Problem
Organization: Whole Earth 'Lectronic Link
Date: Fri, 6 Nov 1992 07:27:01 GMT

In article <1992Nov3.113121.3388@ntuix.ntu.ac.sg> gthkoh@ntuix.ntu.ac.sg (Koh Thong Hwee) writes:

> [define class B which references class A which references class B]

In C++ you can specify a forward reference to a class by just saying:

class <class-name>;

In that header module you can then declare a member variable to that class.

Ex:

class A;

class B {
private:
   class A *foo;
};

then go on to define your cyclic relation:

class A {
private:
    class B *bar;
};

This should solve your problem.  You also want to be careful about using
inline funcitons within your class definitions.  If you reference a member
function of class A when you define an inline function within class B you
will run into trouble because class A has not been defined yet.


Sean Donovan
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c++
Subject: Re: Squares and Rectangles (Re: Const Inheritance)
Date: 11 Nov 92 22:16:46 GMT
Organization: negligable

You might be happier with my setSize()/setAspectRatio() paradigm
that I have just suggested in a different branch of this thread.

I think that those generalize much better than setWidth()/setHeight()!

How many other ways to design a geometrical heirarchy are there? :)


		-Richard Hartman
		hartman@uLogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Disco isn't dead...			...it's just in witness protection!

Newsgroups: comp.lang.c++
From: pandrews@lovat.fmrco.com (Paul Andrews)
Subject: Re: operator [][]
Reply-To: pandrews@lovat.fmrco.com
Organization: Fidelity Investments Ltd.
Date: Thu, 12 Nov 1992 09:48:13 GMT

In article 13511@ucc.su.OZ.AU, maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
> In article <1992Nov9.114516.29846@alf.uib.no> s026@brems.ii.uib.no (Paal K Holmberg) writes:
> >In article <1992Nov9.095352.19114@fmrco.uucp>, pandrews@lovat.fmrco.com (Paul Andrews) writes:
> >|> 
> >since it os a trouble to get around mutiple []'s , you can always cheat and use a 
> >normal function element(int x,int y...) to get a certain element in the matrix or whatever.
> >I agree it is not as elgant as the [] approach, but it is easy.
> >
> 
> 	It would be nice if [] could work like (), that is one could
> declar
> 
> 	operator[](int,int,int){ ...}
> 
> for example, that is, allow multiple arguments for [] just like ().
> This would allow multiple dimensioned matrices as well as providing
> a wealth of extra overloadable notations.
> 
> It would of course break those programs for which
> 
> 	a[2,3];
> 
> actually meant a[3] using the comma operator, but there surely are not
> so many of them ..??
Ah yes, one could of course overload the , operator for some sort of 'index' class
and then overload the [] operator using class index as the argument...

class index
{
...
	operator,(int) ...
...
};

class matrix
{
...
	operator[](index&)
...
};

---
---
Paul Andrews

EMail		Internal	External
pandrews@lovat	8-727-4723	44-71-975-4723

Newsgroups: comp.lang.c++
From: brianm@cc.gatech.edu (Brian N. Miller)
Subject: Constructor order
Organization: Georgia Tech College of Computing
Date: Fri, 13 Nov 1992 16:06:59 GMT

Does a parent's constructor get called before or after the class's constructor?

How about destructors?
Newsgroups: comp.lang.c++
From: amitp@rice.edu (Amit J. Patel)
Subject: Re: PROPOSAL: Hidden private parts of classes
Originator: amitp@aten.cs.rice.edu
Reply-To: amitp@owlnet.rice.edu
Organization: Rice University
Distribution: usa
Date: Fri, 6 Nov 1992 14:18:32 GMT


In article <1992Nov4.200426.24424@netcom.com>, ort@netcom.com (David Oertel) writes:
|> 
|> I'd like to make a pragmatic point concerning not exposing your private parts.
|> My 15k line program brought my 33mhz 486 to its knees until I started using 
|> this technique.  Header file dependencies cascade rapidly and tend to force 
|> a near full-rebuild when a header file needs changing.
|> 
|> ort@netcom.com
|> -- 

Same here!  :)

Perhaps the solution lies in the programming environment --- maybe our
notion of "header" and "code" files needs to be changed.

Maybe:


Public Interface	.h	-> gets #include-d
Private structure	.hp	-> gets compiled to .op
Code			.cc	-> gets compiled to .o

The makefile would have two sets of files to compile:

	1 - compile all .hp files to .op files; if a .hp file
	    includes A.h, and A.h is changed, A.hp must be
	    recompiled.  This will produce a .op file which
	    describes the structure to the compiler

	2 - compile all .cc files to .o files; if it includes
	    a .h file that needs private stuff, the compiler
	    can look in the .op file for the layout.  Since it's
	    already parsed & converted to internal form, it should 
	    be fast.

Does this seem reasonable?  An implementor can give out .h and .op
files, so that the user doesn't see the .hp file.  The .hp file
doesn't have to be recompiled every time, and those of us with 486s
don't have to wait for hours recompiling.  :)

		

			Amit



P.S.  Building my 4000 line program manages to get **150,000***
      lines after all the #includes.  It drives me up the wall!
Newsgroups: comp.lang.c++
From: nickel@unison.com (Jody Nickel)
Subject: Re: Liant C++ Views Support
Date: Fri, 13 Nov 1992 06:42:29 GMT
Distribution: ?
Organization: Unison-Tymlabs
Keywords: C++ WINDOWS DOS LIBRARIES

I must apologize to both the readers of this posting and more importantly
to Liant for the original posting, although I am somewhat unhappy with their
front line support personnel. After calling several times, trying to verify
that there was indeed a charge for support for C++/Views, they gave me the 
direct line to the C++/Views support team instead of a pre-sales support 
person.
I called this number and reached Stan Schroeder, the manager of support for
C++/Views. He assured me that there are NO charges for support, there never 
has been and are no plans to. He was very interested in finding out who 
told me that there would be and was VERY helpful in resolving my problem.

I must apologize again to Liant for erroneously bashing their support. Although
I wish that their front-line support was more attentive and would have 
properly routed me to Stan earlier, the end result was an answer to my 
question and a renewed faith in C++/Views.
Sorry to congest news with this, but I felt obliged to correct the earlier
posting.
Jody Nickel
Unison-Tymlabs
From: vincent@datmuc.UUCP (vincent)
Newsgroups: comp.lang.c++
Subject: Re: FAQ request
Date: 6 Nov 92 12:01:23 GMT
Organization: DAT

In article <2600001@hpldsla.sid.hp.com> csteeves@hpldsla.sid.hp.com (Carl Steeves) writes:
 >I have been unsuccessful at obtaining a copy of the FAQ for 
 >comp.lang.c++ by the standard methods described in this notestring.
 >
 >Please email me a copy.
 >
 >Thanks in advance, 
 >
 >Carl Steeves	(csteeves@sid.hp.com)

Me too, I tried the mail command given in a previous acticle
and ziltch:

vincent@datmuc.dat.de
From: 00mebenbenek@leo.bsuvc.bsu.edu
Newsgroups: comp.lang.c++
Subject: HELP
Date: 11 Nov 92 01:56:47 GMT
Organization: Ball State University, Muncie, In - Univ. Computing Svc's


	I'm a college senior majoring in MIS.  As a requirement I took a 
COBOL programming course.  I since have realized that I will more than likely
not be programming in COBOL.  From what I understand I will probably be using
C or C++. I'm undecided on whether I should get traing on C or C++.  Is there
anyone out there that could tell me which one whould be the best one to learn
and why.  I would also like to find out the major differences between the two.
I would appreciate any responses that I get....


							THANKS
							Mike @BSU
Newsgroups: comp.lang.c++
From: dkarr@sierra.com (David Karr)
Subject: Re: Debugging output
Organization: Sierra Geophysics,  Kirkland WA
X-Newsreader: Tin 1.1 PL4
Date: Fri, 6 Nov 1992 18:41:26 GMT

spuler@coral.cs.jcu.edu.au (David Spuler) writes:
: 
: [Sorry if this is a re-post. The first one seemed to get lost.]
: 
: I was wondering whether anyone has any suggestions as to how to use the neat
: operator << to produce debugging output in a way that it can be removed
: easily from production code.  The obvious method is:
: 
: #ifdef DEBUG
:    cerr << .....
: #endif
: 
: but I'd like to avoid the #ifdef -#endif lines.
: 
: I've been trying to declare my own "dbg" streams by inheriting it
: from the standard "ostream" class and redefining the << operators.

I don't know of an elegant way to remove the generated code, but you can
implement a derivative of streambuf that will allow you to suppress the
debug output at run time (from the environment).

In the streambuf derivative, override the "overflow" method such that
before sending the data out, call a ptr to function which sends the data to
be sent out to a "filter" function (the ptr to function is set in the
streambuf constructor).  If your environment indicates that you don't want
the debugging output, then your function will return False from the
"filter" function, which will cause "overflow" to not use the characters.

I got a hint on how to do this from the book "AT&T C++ Language System",
distributed by CenterLine Software (with ObjectCenter).
--
David M. Karr
Sierra Geophysics, Inc.
ARPA: dkarr@sierra.com, UUNET: uunet!sgihbtn!dkarr
Phone: (206) 822-5200 (x343)
From: dmp@gasco.uucp (David Ply x1566)
Newsgroups: comp.lang.c++
Subject: Re: Where can one buy an elegant and efficient library?
Date: 5 Nov 92 18:31:12 GMT
Article-I.D.: gasco.1992Nov5.183112.2173
Organization: Northwest Natural Gas, Portland, OR

Does anyone out there have any experience, pro or con, regarding the Booch
Components libraries?  I've seen positive magazine articles for both it and the
Rogue Wave libraries, but nothing on the net.  From what I understand, Booch
Components use templates extensively, but apart from requiring a compiler with
template support, I do not have a feel for this being good or bad.  Is code 
bloat from instantiated templates a problem?  How about flexability? 

I understand that Booch Components have evolved from Ada libraries and Rogue
Wave follows more of a Smalltalk approach.  Not knowing Ada or Smalltalk I do
not have a feel for relative advantages/disadvantages.  Any comments?
(No, I'm not deliberately trying to start a flame war :-) )

Thanks,
Dave
From: danw@jacobs.CS.ORST.EDU (Dan Whitaker)
Newsgroups: comp.lang.c++
Subject: Re: Where can one buy an elegant and efficient library?
Date: 6 Nov 92 06:52:25 GMT
Article-I.D.: leela.1992Nov6.065225.269
Organization: Computer Science Outreach Services - Oregon State University

In article <1992Nov5.183112.2173@gasco.com> dmp@gasco.uucp (David Ply x1566) writes:
>Does anyone out there have any experience, pro or con, regarding the Booch
>Components libraries?  I've seen positive magazine articles for both it and the
>Rogue Wave libraries, but nothing on the net.  From what I understand, Booch
>Components use templates extensively, but apart from requiring a compiler with
>template support, I do not have a feel for this being good or bad.  Is code 
>bloat from instantiated templates a problem?  How about flexability? 
>
>I understand that Booch Components have evolved from Ada libraries and Rogue
>Wave follows more of a Smalltalk approach.  Not knowing Ada or Smalltalk I do
>not have a feel for relative advantages/disadvantages.  Any comments?
>(No, I'm not deliberately trying to start a flame war :-) )
>
>Thanks,
>Dave

I don't want to make this an advertisement, but I do want to keep 
everyone up to date.  The Rogue Wave class library of Tools.h++ is 
a foundation data structures class library.  The collection classes part
come in three different flavors.
 
       1.  Template based collection classes.
       2.  Smalltalk type collection classes.
       3.  Generic type collection classes (using generic.h).

All three have their advantages.  Some very basic, like some compilers
don't support Templates.  Our general feeling is that "real" Template 
based classes are the best way to go most the time.  A good thread to
talk about would be when to use Smalltalk classes and when to use
Template based classes.

On another note, we would like your help.
Rogue Wave is making updates to the foundation class library as we
speak.  This update is a final pass before it goes to several
compiler vendors.  We want to get any feedback that you have
on foundation class libraries before we finalize this release.
If you have any comments on our library or foundation classes
in general please send them to us.  We really want your input.

Dan Whitaker at danw@roguewave.com
Or call our office at 503 754-3010
Newsgroups: comp.lang.c++
From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
Subject: Re: Making qsort type-safe
Date: Thu, 5 Nov 1992 12:59:47 GMT
Organization: University of Birmingham

In article <1992Nov4.162131.10289@cs.brown.edu>, sdm@cs.brown.edu (Scott Meyers) writes:
> So I thought of doing this:
> 
>     typedef int (*CMP)(const void*, const void*);
> 
>     template<class T>
>     inline
>     void safeQSort(T array[], int arraySize,
>                    int (*cmp)(const T *val1, const T *val2)) 
>     {
>         qsort(array, arraySize, sizeof(T), (CMP) cmp);
>     }
> 
> But casts make me queasy, especially so after the mail I got telling me
> about bit pattern conversions when types change.  So -- is this a safe
> thing to do, or does the devil lurk within?

Other responses address the possibility that you could write the wholw qsort in
C++. In answer to your direct question yes the devil does lurk within. It is
possible for a conforming compiler to generate code from your source that will
not work - it is however very unlikely. (I'm sure loads of people will now tell
me of compilers that would fail in this case).

    \\   ( )  NO BULLSHIT! from BAM (Brian McCauley)          
 .  _\\__[oo  ============
.__/  \\ /\@
.  l___\\     E-mail: B.A.McCauley@bham.ac.uk
 # ll  l\\ 
###LL  LL\\