HDTenEightyP/NetNews huggingface dataset:
From: kanze@us-es.sel.de (James Kanze)
Subject: Re: streams
Organization: SEL
Date: 14 Oct 92 10:37:01

In <Bw2CnI.LpB@news.cso.uiuc.edu>, Mike Krupicka writes:

|> I am writing some code where I would like to be able to read in either from
|> stdin or from a file. What I want to know is how do you initialize the stream,
|> and pass it to a common var. I tried something like the following and had
|> problems because the code was local only to the if statement.

|> main(){
|> .
|> .
|> if (stdflag)
|>  ostream& fin = cin;
|> else
|>  ofstream& fin("test.in");

|> Any ideas?

Somebody's sure to point out a better way, but it can be done with a
pointer, ie:

    main()
    {
        ostream*        finPtr ;
        if ( stdflag )
            finPtr = &cin ;
        else
            finPtr = new ofstream( "test.in" ) ;
        ostream&        fin = *finPtr ;
        //  ...
        if ( ! stdflag )
            delete finPtr ;         //  Close file
    }

For that matter, you could probably do:

    main()
    {
        ostream&        fin = stdflag ? cin : new ofstream( "test.in" ) ;
        //  ...
        if ( ! stdflag )
            delete *fin ;           //  Close file
    }

Which one you prefer is a matter of taste.

BTW, your code is a perfect example of why the declarations are local
to the if statement.  In one branch, fin has a type of ostream, in the
other, of ofstream.  So which type is it to have after the if.  (C++
requires compile time type binding.)
--
James Kanze                         GABI Software, Sarl
email: kanze@us-es.sel.de           8 rue du Faisan
                                    67000 Strasbourg
                                    France
Newsgroups: comp.lang.c++
From: bilan@acs.ucalgary.ca (Bohdan Jens Bilan)
Subject: pointers to class functions
Date: Sun, 11 Oct 92 02:41:48 GMT
Organization: The University of Calgary, Alberta

Can anybody tell me how to get the address of a function from
within a member function of the same class?

Thanx


Newsgroups: comp.lang.c++
From: sdm@cs.brown.edu (Scott Meyers)
Subject: Re: My objects are too big - why?
Organization: Brown University Department of Computer Science
Distribution: comp
Date: Fri, 9 Oct 1992 17:50:14 GMT

In article <DOUG.92Oct9093158@monet.ads.com> doug@monet.ads.com (Doug Morgan) writes:
| C++ guarantees all objects have nonzero size, therefore the nonzero
| sizeof(Base).  I've never been able to completely follow the ARM's
| statements about subobjects, but I suspect they somehow imply that
| memory space for derived classes can't be reused for data members if
| already set aside by a base class.  This and (probable) fullword
| alignment requirements give the sizeof(Derived) = 8.

This is contrary to my understanding of the situation.  I was under the
impression that a compiler is allowed to play games such that

                      sizeof(Derived) = sizeof(Base)

if either is empty.  (Actually, I thought that due to the strange rules
governing layout of class members, this might even be true if neither class
is empty.)  For the particular example being bandied about, I thought that
it was possible for sizeof(Derived) = sizeof(int) because the padding
character added to the Base class could be omitted for Derived objects.  Is
this not true?

Scott

-------------------------------------------------------------------------------
What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."
Newsgroups: comp.lang.c++
From: laufer@math.luc.edu (Konstantin Laufer)
Subject: Dispatching bug in g++?
Reply-To: laufer@math.luc.edu
Organization: Loyola University Chicago
Date: Fri, 16 Oct 1992 20:53:04 GMT

Excuse me if this is already a well-known bug, but I don't read this
group regularly.  Consider the following program:

#include <stream.h>

class P {
public:
  virtual void hello() { cout << "hello\n"; }
  void callhello() { hello(); }
};

class C : public P {
public:
  virtual void hello() { cout << "hullo\n"; }
};

void g(P x) { x.callhello(); }	// should call P::hello()

int main() {
  C z;
  z.hello();			// calls C::hello()
  g(z);				// results in an erroneous call to C::hello()!
}

When compiled with g++ 2.2.2 under SunOS 4.1.2, this program produces
the erroneous output
	hullo
	hullo

This is incorrect, since the x is a value parameter, whence
dispatching should be static.

Compilation with AT&T CC correctly results in
	hullo
	hello

Have other people observed this problem?
-- 
-Konstantin [laufer@math.luc.edu]
From: exudch@exu.ericsson.se (Doug Hurtig, t/foj, (214) 997-6571)
Newsgroups: comp.lang.c++
Subject: ostrstream problem?
Date: 13 Oct 92 15:49:28 GMT
Reply-To: exudch@exu.ericsson.se
Organization: Ericsson Network Systems
X-Disclaimer: This article was posted by a user at Ericsson.
              The opinions expressed are strictly those of the
              user and not necessarily those of Ericsson.

I have an application running on a Sun 4.1.1 system that uses
ostrstream to build up a charater array.  Once I have built the array
I use "str" to get a pointer to the charater array and to freeze the
array. It is my understanding that I am responsible for releasing the
memory once the "str" function is called.
 
During testing of this code I have noticed that when the destructor
is called several bytes are appended to the array returned by str.
This is a problem in that the array has already been freed. In my real 
application this memory has already been reallocated by time the ostrstream
destructor is called.

Actual problem is occurring in streambuf::sync which is called by
ios::~ios from ostrstream::~ostrstream when get_str returns.  This
problem was initially detected by a memory allocation debugging
tool.  To verify this problem, I used dbxtool to stop in get_str after
the call to outs.str(). At this point I changed the 17, 18 and 19
charaters in str to known values and then continued execution. When
control returned to main each of these bytes contained "\0".

example:

	#include "strstream.h"
	#include "iostream.h"
	#include "string.h"

	char * get_str()
	{
  	  char * str = NULL;
  	  char * p = NULL;
 	  ostrstream outs;
  
	  outs << " this is a test " << ends;
	  str = outs.str();
	  p = new char[ strlen(str) + 1 ];
	  strcpy( p, str );
	  delete str;
	  return p;
	}

	main()
	{
	  char *a_str;
  
	  a_str = get_str();
	  cout << a_str << endl;
	  delete a_str;
	}


Is this a known problem with the ostrstream class or am I doing something wrong? 


Thanks,

Doug
Xref: sparky comp.lang.c++:14834 comp.std.c++:1369
From: nickn@manutius.UUCP (Nick Nussbaum)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: The concept of templates considered ill designed
Date: 10 Oct 92 22:29:09 GMT
Reply-To: nickn@manutius (Nick Nussbaum)
Followup-To: comp.lang.c++
Organization: Aldus Corporation, Seattle WA

I'm looking for a c++ preprocessor that converts template notation into
macros for older c++ compilers. I recall seeing a mention of such about
a year ago. Does anyone have a reference?
Thanks.
Newsgroups: comp.lang.c++
From: nh@cbnewsg.cb.att.com (nicholas.hounsome)
Subject: Re: Shallow & Deep copies of objects
Organization: AT&T
Date: Wed, 7 Oct 1992 08:20:24 GMT

From article <92280.110023U45561@uicvm.uic.edu>, by Dimitrios K. Valsamis <U45561@uicvm.uic.edu>:
> Could anyone explain to me what is a Shallow and a Deep copy of an object? How
> easy is to implement functions for perfoming those operations on ANY kind of
> object?

A shallow copy is what you get in C and also in C++ if you do not define
a copy constructor and an assignment operator. It does not copy whatever
any pointers you have in your object point to.

A deep copy (deep) copies objects pointed to as well.

eg if you shallow copy the root of a tree you would then have two roots to the
same tree. If you deep copy the root of a tree you will have two identical
but distinct trees.

> 
> One more question that I am have is dealing with the new and delete operators.
> When do we usually overload those operators?
> 

You almost never overload new or delete - it would  be equivalent to
redefining malloc and free in C.

You usualy want to define a (virtual) destructor for any class for 
which you want a deep copy - this is so that you get a "deep destroy" as well!
You will want to delete any objects that you point to. The default
here again is a "shallow destroy".

> Sorry if these are FAQs!
> 
> Thanks in advance,
> 
> Dimitrios Valsamis     e-mail : valsamis@earth.eecs.uic.edu
>                                 u45561@uicvm.uic.edu

In summary if your class creates any objects then it probably wants to
do deep copying and destroying and should look something like:

class X
{
public:
	X(X&);
	X& operator =(X&);
	virtual ~X();
private:
	Y *pointer;
}
From: djd@csg.cs.reading.ac.uk (David J Dawkins)
Newsgroups: comp.lang.c++
Subject: Re: (none)
Date: 7 Oct 92 10:44:45 GMT
Organization: University of Reading

>In a message of < 1-Oct-92 11:25> Yann David (92:901/-24472) wrote:

> YD> It seems that the linker does not recognize those static
> YD> variables. For example, the following program:

> YD>   class MyClass
> YD>   {     static int a=0;
> YD>     public:
> YD>         void incA();
> YD>   };

You need to declare storage for any static class variables you use.
Typically, you would do:

Foo.h:
    class Foo {
        static int a;
        };

Foo.c:
    int Foo::a = 0;

I think our compiler (AT&T 3.0.1) will actually create storage for "simple"
types. Your mileage may vary.

-dave

-- 
djd@csg.cs.rdg.ac.uk
djd@csug.cs.rdg.ac.uk
davidd@integ.uucp
From: osstlm@eua.ericsson.se (Tomas Lundstrom)
Newsgroups: comp.lang.c++
Subject: new ODBMS product release
Date: 16 Oct 92 17:32:52 GMT
Reply-To: osstlm@eua.ericsson.se
Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden



I have posted a description of the latest EasyDB ODBMS product to
comp.newprod and eunet.newprod. Read it !

For further information, please contact Renee Sjostedt, Jaan Haabma or Per-Arne 
Gussander at Objective Systems SF AB on:

	phone: +46 8 703 45 30, fax: +46 8 750 80 56,
	E-mail: base-open-request@os.se


Product Summary

	EasyDB releases 3.1 product highlights are summarized in:

*	Multi-user system with network distributed storage - can be scaled down 
	to single-user and single-host configurations.

*	Strong modeling system (both graphical and textual). Dynamic schema 
	evolution.

*	Well integrated language bindings (C, C++, Ada in Q2 -93).
	Static or dynamic name resolution. Multimedia support.

*	Safe and easy to use conflict handling throughout the system.

*	Support for Configuration Management.

*	Powerful distribution mechanism. Network topology independent.

*	Technology independent layers.

*	High performance. Short and long-lasting transactions.


/Tomas
Newsgroups: comp.lang.c++
From: rigg@ssdt-tempe.sps.mot.com (Dana Rigg)
Subject: Class Testing
Reply-To: rigg@ssdt-tempe.sps.mot.com
Organization: Motorola, Inc.
Date: Thu, 8 Oct 1992 16:46:49 GMT

Hello all!

I'm interested in any papers discussing class testing in C++.
Implementations or personal ideas are welcome but no random shots
please, only well thought-out plans.  I'm looking for something
formal, simple enough so that test code does not require a lot of
formal testing, and easily adaptable to numerous classes.

Please resond by email, as I don't read this newsgroup all that
frequently.

Thanks very much for you help!

Dana Rigg
Chandler, AZ.
rigg@ssdt-tempe.sps.mot.com
From: mb7r+@andrew.cmu.edu (Massimo Bigliardo)
Newsgroups: comp.lang.c++
Subject: C++ Croos reference
Date: 7 Oct 92 18:31:55 GMT
Organization: Philosophy, Carnegie Mellon, Pittsburgh, PA

Does anyone knows if there is any program for cross referencing c++ programs?
I need something like it in order to document a program written in c++.
It would be useful to know the files where the classes are defined, the
sequence of function calls (who calls who) and so on. I had one for
Common Lisp.
The program should run on unix vaxstations under X.
Since it is the first time I work with c++ code, I am not used to read
this group. Please send ny pointer /suggestion directly to me.
Thanks
--Massimo
Newsgroups: bnr.lang.c++,comp.lang.c++
From: dak@tabaqui.informatik.rwth-aachen.de (David Kastrup)
Subject: Re: Is pointer in my address space?
Keywords: process address memory pointer
Organization: Rechnerbetrieb Informatik  /  RWTH Aachen
Date: 12 Oct 92 21:56:44 GMT

crlstu4@bnr.ca (Goetz von Escher) writes:


>Hi there!

>Is there a way to find out if a pointer is a valid pointer in C/C++?
>Or in other words: If I want to read a value in memory, how do I
>know wether I can read the value at this address without causing
>an exception (bus error, segmentation fault and that stuff)?

>Anything?
>Goetz
The ARM says you can't. Burn candles and sing. On the other side, if
you have to check whether you can store your values, you have a lousy program.
One does not just use any memory which does not cause a violation, you
know. If you really are into muck, try catching the segmentation violation,
and other signals. You will have to return through some setjmp/longjmp-
construct, but this stinks. If you get a violation, it
has good reason. Trying in any way to ignore or circumvent it is
madness. Be glad the MMU is there to protect you from your folly!
Newsgroups: comp.lang.c++
From: dcb@slsvitt (David Binderman 3841)
Subject: Re: Nested classes & Inheritance
Organization: SEL-Alcatel LTS Dept. US/ES
X-Newsreader: Tin 1.1 PL4
Date: Wed, 14 Oct 92 09:16:18 GMT

bs@alice.att.com (Bjarne Stroustrup) writes:
: 
: dcb@slsvitt (David Binderman 3841 @ SEL-Alcatel LTS Dept. US/ES) writes
: 
:  > Given the following code
:  > 
:  > class A {
:  > public:
:  >      class B { };
:  > };
:  > 
:  > class C : public A {
:  >     class D {
:  >         B y;
:  >     };
:  > };
:  > 
:  > Then does the declaration of y require A::B or only B ?
:  > Or, is B accessable from D directly ?
:  > 
:  > The ARM, Stroustrup 2 & Lippmann 2 didn't help in this case.
: 
: Well, the lookup rules in 10.4 of the manual (in the ARM or my 2nd
: edition) ought to have helped. In a class, having looked locally,
: you start looking for names in base classes. B is a name is the
: scope of A so that the B in `B y;' must refer to A::B.
: 
: Names of nested classes obey all the usual lookup rules for member names.

Unfortunately, I looked at section 9.7 fourth sentence, which is the
last sentence on page 185 in my copy of the ARM.

The sentence seems to me to contradict the advice in 10.4 section.

My understanding is that class D doesn't have class A as a base
class, and so has no knowledge of its contents.


Regards

--
David C Binderman     Dept US/ESI, Bau 60, SEL-Alcatel AG, Lorenz Strasse 10,
D-7000 Stuttgart 40, Germany      dcb@us-es.sel.de   Tel: +49 711 821 3841
If you lie to the compiler, it will affect your parents' credit rating :->
From: bastide@cix.cict.fr (Remi Bastide)
Newsgroups: comp.lang.c++
Subject: Looking for graph-drawing classes
Keywords: Graphics, X11
Date: 14 Oct 92 17:30:22 GMT
Organization: Centre Interuniversitaire de Calcul de Toulouse

I am starting to write a graphical editor for a special dialect of Petri-Nets.
I wonder if i can find somewhere ftp'able c++ classes that handle the 
common task of drawing 'nodes connected by arcs'. The only requirement is
that the classes must be built on top of X11 (Xlib, Xtk).

Thanks for any help
From: ges@stiatl.salestech.com (Gerald Sullivan)
Newsgroups: comp.lang.c++
Subject: Re: My objects are too big - why?
Date: 13 Oct 92 10:33:16 GMT
Organization: Sales Technologies, Inc.

nikki@trmphrst.demon.co.uk (Nikki Locke) writes:


>In article <23858@alice.att.com> bs@alice.att.com (Bjarne Stroustrup) writes:

>> 	The reason abstract classes are underused in C++ (in my opinion)
>> 	is not implementation problems, but ignorance about their uses and
>> 	overuse of hierarchies based on ``universal'' classes.
>Another reason is that at least two of the most popular MsDOS-based C++ 
>compilers do not implement them properly, so that mixins do not work 
>correctly.

>Unfortunately (?) more than half the C++ programmers in existence use 
>these DOS based compilers.
>---
>Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
>trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.

Could you please elaborate what is improper? 
I have used Zortech 2.0 and Borland 3.0. I am currently using Borland. 
I use abstract classes as mixins extensively. 

I have had no known problems.

Thanks.


-- 
___________________________________________________________________
Jerry Sullivan, Sales Technologies, Inc.  Atlanta,GA 
ges@salestech.com,...uupsi!stiatl!ges I don't speak for my employer.
Just say no to Republicrats, vote Libertarian.
Xref: sparky comp.lang.c++:14745 comp.std.c++:1354
From: osoelgaultier+@CMU.EDU (Stefan Monnier)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: The concept of templates considered ill designed
Date: 8 Oct 92 12:43:58 GMT
Article-I.D.: andrew.Iep9qCe00Vp_M390kE
	<23829@alice.att.com>
Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA

Excerpts from netnews.comp.lang.c++: 7-Oct-92 Re: The concept of
template.. Andrew Koenig@alice.att. (991)

> In article <IeoW7Ca00awVEGbFIn@andrew.cmu.edu> osoelgaultier+@CMU.EDU
> (Stefan Monnier) writes:

> > What's the problem ?

> > Why not take option 2 ?

> > Every Baz object has method Foo::mem(int) cause it has inherited it
> > from Foo.
> > If you don't agree with it, why use inheritance ?

> Well, let's make it more explicit.

> 	class Foo {
> 	public:
> 		void mem(int);
> 	};

> 	class Bar: public Foo {
> 	public:
> 		void mem(int);
> 	};

> 	template<class T> void f(T x) { x.mem(); }

> 	main()
> 	{
> 		Bar b;
> 		f(b);
> 	}

> The whole point of templates is that the call f(b) should result in
> calling Bar::mem, because b is an object of type Bar.

> What you're saying is that you want f(b) to call Foo::mem if the template
> function f has a constraint that T is Foo or derived from Foo.
> It's already easy to obtain such behavior -- just don't bother with
> templates at all!

> In other words, I don't think option 2 is viable.  Do you still think
> so after seeing this example?
> -- 
> 				--Andrew Koenig
> 				  ark@europa.att.com


Sorry, but the original problem was a bit different, cause it uses overloading:


-For example, suppose we have a class:
-
-	class Foo {
-	public:
-		void mem(int);
-	};
-
-and a template function:
-
-	template<class T> void f(T t) { t.mem(0); }
-
-You are saying that constraining T to be of class Foo or a class
-derived from Foo will make it possible to type-check this template
-at compile time.  Wel, what about this?
-
-	class Bar: public Foo {
-	public:
-		void mem(int);
-		void mem(void*);
-	};
-
-If we call f with an argument of type Bar, it will fail during instantiation
-with an ambiguity error.  The only way to avoid this is to say that the type
-constraint also constrains the call of t.mem(0) to just those instances of
-mem defined in the base class -- but in that case, you will still get in
-trouble with this one:
-
-	class Baz: public Foo {
-	public:
-		void mem(long);
-		void mem(double);
-	};
-

Here, I suggested to call Foo::mem(int) (or Bar::mem(int) if it exists) cause, 
at compile time, mem(0) can only be linked to mem(int) (the others are
unknown) and because there  is no reason to link it to anything else (in
fact, the only other alternative I can see is to announce an ambiguity)

But of course if the inherited method is overridden, the new one should
be called
(but a method with same name but different arguments is not considered to be
the same method: it's not overriden)

	Stefan

-----------------------------------------------------
-- On the average, people seem to be acting normal --
-----------------------------------------------------
Newsgroups: comp.lang.c++
From: bill@snoopy (Bill Poitras)
Subject: (QUERY) How to call an object's member function?
Reply-To: bill@msi.com
Organization: Molecular Simulations, Inc.
X-Newsreader: Tin 1.1 PL5
Date: Fri, 16 Oct 1992 06:30:11 GMT

In Unix, under any widely availible debugger, how do you call a method on
a variable:

#include <stdio.h>
#include <string.h>
class String {
public:
  String(const char *str) { str_ = strcpy(new char[strlen(str)+1], str);
};
  String():str_(0) {};
  const char *value() const { return str_; };
private:
  char *str_;
};

main()
{
  String a = "Hello";
  String b[100];

  printf("a is \"%s\"", a.value());
}

After the constructor for 'a' I stop (line 15).  In both gdb 4.6 and dbx
for Sun C++, I type 'print a.value()'.  I get some bullshit about value
not being a member of the structure.  What the hell is going on?   Why
can't I call a simple method?  I compiled this code both with Sun C++ and
gcc 2.2.2.

--
+-----------------+-------------------------------+-------------------------+
| Bill Poitras    | Molecular Simulations Inc.    | Tel (408)522-9229       |
| (bill)          | Sunnyvale, CA USA             |                         | 
|                 | FAX (408)732-0831             | bill@msi.com            |
+-----------------+-------------------------------+-------------------------+

Newsgroups: comp.lang.c++
From: bmaslen@julian.uwo.ca (b.   maslen)
Subject: how to shrink a window with graphics
Organization: University of Western Ontario, London
Date: Thu, 8 Oct 1992 00:18:21 GMT


what I want to do is to make a window and put in it a part of a map.
After I draw in the map (taking up pretty much the whole screen), I want to be able to compress it into a smaller window and store it on the screen.

When I went to view that window again, it would be brought up on the screen the size that I had typed it in.


Is there a way to do so???
If so, can you give me an idea??????

Thank you in advance!!!!!
Newsgroups: comp.lang.c++
From: emike@sdc.com (E. Mike Durbin)
Subject: Re: C++ for Sparcs: recommendations?
Organization: Systems Development Corporation
Date: Wed, 7 Oct 1992 14:22:27 GMT

In article <39052@sdcc12.ucsd.edu> pluto@cs.ucsd.edu (Mark Plutowksi) writes:
  >
  >Dear Cross-Training C++ Wizards, (i.e., you use both PC & Sparc)
  >
  >Is there a C++ compiler for Sparc stations that 
  >
  >	- is up to date with the Real Thing (the Xerox "standard")

I wasn't aware that there was a "Xerox" standard for C++.

  >	- is cheaper than the Real Thing

If free cheap enough?

Define "the Real Thing":
    100% Compatiablity with AT&T Cfront?
    Which version?

  >	- has a gui debugger with keyword-sensitive on-line help
  >	- has object browsing
  >	- has project management (I haven't used make.exe all year.)

I just got my brand new copy of SPARCworks Professional C++ 3.0
which does all of this (but I haven't played with it yet).

  >	- has gui-building capabilities ala BC++'s OWL & Protogen,
  >	  but for X Windows instead.

There are lots of C++ based gui buildes, and even more C based gui
builders.  Some, such as Objectcenter and (presumably) ParcPlace
(both of which supply the Solbourne C++ toolkit and GUI builder)
provide compilers, debugger, browsers, etc., as well.  (I use and
VERY MUCH like the Solbourne C++ toolkit).

  >Or, must I bite the bullet and purchase the Real Thing along with
  >some kind of X Windows gui-building tools?   Come to think of it,
  >does the Real Thing satisfy the above list?
  
Again, define "the Real Thing".
I could solve your development problems a dozen or more different ways.

  >Signed,
  >
  >"Sticking With My PC Until My Sparc Becomes More User-Friendly
  >But My Super Wants Me To Use The Expensive SparcStation
  >He Bought Me But For Which He Didn't Reserve Any Money For A 
  >Decent Compiler And My Project Will Be Over Before Sun Comes Out
  >With Their Next Version" in San Diego.

Ignorance is bliss :-)

Sorry, couldn't resist.

Check out the GNU compilers, SPARCworks Professional C++ (Requires
Solaris 2.0) and the Objectcenter or ParcPlac C++ GUI (Based on
Solbourne's OI toolkit) and compilers environments.

E. Mike Durbin
emike@obs.com or emike@sdc.com