HDTenEightyP/NetNews huggingface dataset:
From: chw@bellcore.com (Charlie Woloszynski,MRE 2J-278,8295228,,27143)
Subject: Question of scope
Reply-To: chw@bellcore.com
Organization: Bellcore
Date: Fri, 22 Jan 93 18:45:58 GMT


A (novice) question about scope.
 
 
I have a class Base from which I derive several additional classes, as in:
 
class Base 
{ 
  virtual Draw(); 
} 
 
class Derived1 : public Base 
{ 
  virtual Draw(); 
} 
 
I need to pass a pointer to an instance of one of these derived classes 
to a function (so I can make use of the derived functions) like:
 
 
void foo(Base *p) 
{ 
  p->Draw(); 
} 
 
Now I generally need to create the Derived classes only to pass them
to foo.  I don't want these instances to exist after the call to foo.
 
Anyway, does the following call the destructor just after returning
from the foo?
 
   foo(& Derived1());
 
Does it have any ugly portability problems? 
 
Charlie Woloszynski
chw@bellcore.com
Newsgroups: comp.lang.c++
From: pete@borland.com (Pete Becker)
Subject: Re: Why X::X(X &a), not X::X(X a) ?
Originator: pete@genghis.borland.com
Organization: Borland International
Date: Sat, 23 Jan 1993 19:23:43 GMT

In article <1993Jan20.130006.1@ualr.edu> hood%eivax@ualr.edu writes:
>In article <884@ulogic.UUCP>, hartman@ulogic.UUCP (Richard M. Hartman) writes:
>> In article <1993Jan15.092416.1@ualr.edu> hood%eivax@ualr.edu writes:
>>>  Since the copy constructor should not normally 
>>>modify the source object a better declaration would be X::X( const X a)
>> 
>> I am assuming a typo.  Shouldn't that be:
>> 
>> 	X::X(const X &a)	?
>> 
>
>Your right, it was a typo; the way you show it is correct.
>

	Just to be sure there's no confusion:

	X::X(X&);	// copy constructor
	X::X(const X&);	// copy constructor

	Both are legal, and both are "correct".  Most of the time you'll want
the const version, but it's not inconceivable that someone might want a
copy constructor that takes a non-const parameter.  The ARM has rules for how
the compiler deals with both types when it has to generate a copy constructor.
	-- Pete
From: tpm@ecs (TP Monks)
Newsgroups: comp.lang.c++
Subject: Re: C++ templates, link simulation.
Date: 21 Jan 93 11:07:53 GMT

I'm using cfront on an sgi machine and have come across a problem.
It appears that the link simulator is not capable of picking up
undefined symbols in libraries.  I had a quick hunt through the doc 
but didn't spot any mention of this... perhaps I was too quick..
							  
In a large project with several libraries, isn't it a reasonable to want to
use libraries containing template definitions, and to link into these
relying on a common repository to allow undefined symbols to be resolved.

Isn't it a pain to have lots of template definition files kicking around
which aren't in a library?
								 
Please could someone point me to a ref for this.

Tim

--
-----------------------------------------------------------------------------
Tim Monks                                Vision, Speech and Signal Processing
tpm@ecs.soton.ac.uk                                    Southampton University
Tel: +44 (703) 592774                                   Fax: +44 (703) 592895
--
-----------------------------------------------------------------------------
Tim Monks                                Vision, Speech and Signal Processing
tpm@ecs.soton.ac.uk                                    Southampton University
Tel: +44 (703) 592774                                   Fax: +44 (703) 592895
From: nikki@trmphrst.demon.co.uk (Nikki Locke)
Newsgroups: comp.lang.c++
Subject: Re: Help w/ default arguments and more
Date: 27 Jan 93 11:32:09 GMT
Reply-To: nikki@trmphrst.demon.co.uk
Organization: Trumphurst Ltd.
X-Mailer: cppnews $Revision: 1.31 $

In article <1jq475INNp69@tamsun.tamu.edu> ski8032@tamsun.tamu.edu (Suman Kumar Inala) writes:
> I would like to be able to do something like this:
> 
> class X {
>     int x;
> public:
>     X(void) { x = 3; }
>     int func(int arg = this->x) { return arg; }
> };
> 
> In other words, I would like the default argument to
> one of a classes methods to be one of the members of
> the class.  This is of course possible if I were
> to make x static, but this is not acceptable.  BC complains
> that this may only be used in member functions; simply
> expressing "int arg = x" gives the legitimate complaint
> that x is not associated with an object.  The
> following is a workaround, but I don't like it much:
> 
> class X {
>     int x;
> public:
>     X(void) { x = 3; }
>     int func(void) { return x; }
>     int func(int arg) { return arg; }
> };
> 
> Is there a better solution?  

I don't think there is. If arg never takes a particular value (e.g. -1), 
then you can do ...
      int func(int arg = -1) { return (arg == -1) ? x : arg; }

This is often most useful for pointer arguments, which you default to 
NULL.

> Also, I know I'm missing
> something simple here, but the following doesn't work:
> 
> 
> #define SWAP_INT(a, b) { a ^= b; b ^= a; a ^= b; }
> inline void swap(int a, int b) {  a ^= b; b ^= a; a ^= b; }
> 
> The SWAP_INT macro works, but not my inline function.  Why?

Because you are passing the arguments by value. An inline function has
exactly the same effect as a non-inline function (indeed, the compiler may
arbitrarily decide not to inline it). You need ...

  inline void swap(int &a, int &b) {  a ^= b; b ^= a; a ^= b; }

> Also, I declared a class Map which contains a 2D array.  I
> would have liked to overload the [] operator to take two
> arguments, so that I could treat it in a natural way,
> indexing the elements of the map using array notation.
> (Is this perhaps bad practise?)
> 
> Map map(80, 20); // Dimensions of map are 80 columns, 20 rows
> 
> cout << map[3][4];
> 
> But the [] operator may only be declared to take one argument.
> It would be nice if the following notation could be used were
> it possible for [] to take more than one argument, though it
> is not traditional C notation:
> 
> cout << map[3, 4];

Surely it would be better to be able to use map[3][4], just like a "real" 
array. There are ways of doing this - usually using a helper class which 
emulates a single dimension of the array. I believe there is an example 
in the FAQ for this group.

-- 
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.
From: schmidt@rz.uni-passau.de (SCHMIDT GUIDO)
Newsgroups: comp.lang.c++
Subject: LEDA for BC++?
Date: Fri, 22 Jan 1993 18:03:24 GMT
Organization: University of Passau - Germany
NNTP-Posting-Host: hiwi170.rz.uni-passau.de
Keywords: LEDA, Borland

Hello!

I recently ftped the LEDA class-library (V. 3.0). I read the infos 
and the documentation. I'm really thrilled by its high level interface 
for complex and efficient data types like hash_arrays, for instance.

But I can only use it with Borland's BC and now I'm trying to convert it
to MSDOS file standards. Many file names use more than one dot or exceed
the 14 character limit. Manual changing is cumbersome and tideous. But
I think there is a script <LEDA>/util/shorten which does exactly this.
Only I don't know how to use it. Has anyone tried to convert LEDA to
MSDOS? Please share your experiences with me. Has anybody created all the
libraries? Maybe it's possible to copy them from somewhere?

Any help appreciated.

Guido
--------------------------------------------------------------------
- Guido Schmidt                                                    -
- schmidt@rz.uni-passau.de                                         -
- Universitaet Passau, Germany                                     -
--------------------------------------------------------------------

Newsgroups: comp.lang.c++
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: operators
Keywords: operators,inheritance
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Date: Tue, 26 Jan 1993 21:47:41 GMT

In article <1993Jan21.165621.16704@jussieu.fr> clerc@gla.ecoledoc.ibp.fr writes:
>
>Id like to express in C++ the fact that operators < <= >= can
>be defined using operators > and = (eg: a < b  is b > a)
>I would use a class MathObj (that would implement < <= >= using > and =)
>and derive my classes from it, redifining only the basic operators > and =
>
>How can I WRITE that in C++ ? (no template solution please)
>

	<cry> You cant, well, you can .. using macros.

	#define stdcmps(T) \
	friend int operator<=(const T& a, const T& b) \
		{ return a<b || a==b; } \
	friend int .....


-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
From: jimi@vnet.ibm.com (Jim Meyers)
Date: Mon, 25 Jan 93 10:37:05 EST
Newsgroups: comp.lang.c++
Subject: Re: Objects in Shared Memory

In <1993Jan19.174651.24907@hellgate.utah.edu> clark%asylum.cs.utah.edu@cs.utah.edu (Charles Clark) writes:
>In article <1993Jan19.082043.4341@dxcern.cern.ch> pvv@cern.decnet.cern.ch () writes:
>>
>>Has anyone tried to do share objects between processes ?
>
>Yes.
>
>>Any advice or reference to an article or a book would be appreciated.
>
>A paper that addresses this problem is:
>
>David Jordan, ``Instantiation of C++ Objects in Shared Memory''.  In ``C++
>at Work '89''.
>
> ...
>
>One way to solve this problem, and the one espoused in the above
>article, is to coordinate the location of virtual function tables within
>all processes accessing shared objects.  Thus, the virtual function
>table for a particular class will reside at the same memory location
>in each process.
>
>The first of these approaches is not complete in that it does not
>address the problem of intra-object references.  Thus, virtual base classes
>can not be used in the inheritance hierarchy of the shared objects.

This is not all clear to me... Can you elaborate on why you believe that
Jordan's method does not support intra-object references?

-------------------------------------------------------------------------
Jim Meyers                           | Voice:    919-543-5999
IBM Networking Systems               | Fax:      919-543-1286
LAN Systems Workstation Technology   |
Research Triangle Park, NC 27709     | Internet: jimi@vnet.ibm.com
-------------------------------------------------------------------------
Xref: sparky comp.lang.c++:19980 comp.object:5078
From: hrpctw@pnv.palm.cri.nz (Colin T. Wilson-Salt)
Newsgroups: comp.lang.c++
Subject: Function 'max' should have a prototype
Date: 25 Jan 93 21:49:41 GMT
Article-I.D.: pnv.hrpctw.14
Organization: DSIR, Palmerston North, New Zealand

I can't seem to get the max() macro to work.  It works OK under C, but
under C++ it gives me the error "Function 'max' should have a prototype".

I can compile the following example code from the Borland C manual
as TEST.C fine:

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
	int x = 5, y = 6, z;
	z = max(x, y);
	printf("The larger number is %d\n", z);
	return 0;
}

but if I rename the file TEST.CPP it won't compile.

Is this an error in the #include file perhaps?

Should I give up and write a replacement max() function/macro?
Newsgroups: comp.lang.c++
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Why is C++ not considered a true OOL?
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Date: Wed, 27 Jan 1993 15:25:06 GMT

In article <ANDY.93Jan22102931@elviss.eng.sun.com> andy@elviss.eng.sun.com (Andrew Davidson) writes:
>In article <1993Jan21.005415.2812@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
>
>>
>>The fourth alternative (mixins) is superior :-)
>>
>>....
>>
>>...
>>
>>But your greatest achievement, Bjarne, in my opinion,
>>was the name dominance rule, because, coupled with virtual
>>bases and abstract classes that enables mixins.
>>
>
>what are mix ins?
>
	So many people have asked that I'm preparing an answer
and some examples. Sorry, its not ready yet.

	Briefly one way to do mixins: 
I declare some 'Axiom' classes with various
interfaces---most of the functions are pure virtual.

	I use Multiple Virtual Inheritance to merge several
of these classes to form a new abstraction. I can also
add new functions defined in terms of the base pure virtuals.
One might call these 'Theorem' classes. They are the user
interface classes.

	The Axioms are useless without implementations.
So I define various implementations that might be useful:
these are the 'Model' classes.

	Finally, I mix up an implementation of my chosen abstraction
be just virtual derivation from the Model classes that I want: some
will be chosen for speed, other for compactness.

	The exact mix of implementation is irrelevant after
the object is constructed: the object is always known
statically by its 'Theorem' name. Implementation details
are hidden, polymorphism does virtual function calls
via from Theorem via the base Axioms and into the
Models (called 'sibling call').

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
Newsgroups: comp.lang.c++,comp.std.c++
From: nikki@trmphrst.demon.co.uk (Nikki Locke)
Subject: Re: Callbacks -- suggested approaches??
Reply-To: nikki@trmphrst.demon.co.uk
Distribution: world
Followup-To: comp.lang.c++
X-Mailer: cppnews $Revision: 1.31 $
Organization: Trumphurst Ltd.
Date: Thu, 28 Jan 1993 13:27:12 +0000

In article <DAVIDM.93Jan25171343@consilium.com> davidm@consilium.com (David S. Masterson) writes:
> I'm looking for suggestions on how to handle callback functions in C++ that
> will be more standard than the one we're currently using.
..
> 	typedef	void	(Process::*Method)(Message*);
> 	struct Callback {
> 		Method		method
> 		Process*	methodthis;	// could be multi-threaded
> 	} table[MAXCALLBACKS];
> 
> Methods would be dispatched like:
> 
> 	void Process::Dispatch(Message* m) {
> 		return (table[Lookup(m)].methodthis->*
> 			table[Lookup(m)].method)(m);
> 	}			
> 
> The registration method for callbacks looks like:
> 
> 	void Process::Register(Method m, Process* p) {
> 		table[i].method = m;
> 		table[i].methodthis = p;
> 	}
> 
> and is called like:
> 
> 	mainproc->Register((Method) MYProcess::callback1, myproc);
> 

Personally, I use templates (or generics) for this sort of thing.
Something like ...

class CallbackBase
	{
public:
	virtual void despatch(Message *m) = 0;
	virtual ~CallbackBase() {}	// Just in case someone creates
			// a new kind of Callback which needs a destructor
	};

template <class X> class Callback : public CallbackBase
	{
	void (X::*method)(Message *);
	X& methodthis;
public:
	Callback(void (X::*m)(Message *), X& t) : method(m), methodthis(t) {}
	void despatch(Message *m) { (methodthis->*method)(m); }
	};

Your table is of CallbackBase pointers.

Methods would be dispatched like:

void Process::Dispatch(Message* m)
{
	table[Lookup(m)]->despatch(m);
}

The registration method for callbacks looks like:

void Process::Register(CallbackBase *p)
{
	table[i].callback = p;
}
 
and may be called like:

mainproc->Register(new Callback<MYProcess>(MYProcess::callback1, myproc));

You do have to take care of deleting the CallbackBase items, but that can 
probably be done in the Process destructor.

[Note - code not compiled or tested, but I do use something very similar.]

-- 
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.
Newsgroups: comp.lang.c++
From: rune@nta.no (Rune Henning Johansen FBA)
Subject: Re: DOS, BC++, Need, large data memory, how?
Organization: Norwegian Telecom Research
	<RUNE.93Jan18151540@calypso.nta.no> <schmidt.25@rz.uni-passau.de>
Date: 22 Jan 93 07:36:36


 > I've tried the following program with TCW 3.0 in model SMALL. It works fine.

Thanks for the program! I didn't know about "farmalloc" before.  But
my problem is that I'm not able to link my program. (I should have
specified that, sorry!) When I'm able to run my program, I guess
"farmalloc" will be very useful in a redefined "new", but until then:
How can I link my program without getting: "Automatic data segment
exceeds 64K"?

 - Rune



Newsgroups: comp.lang.c++
From: wgsteven@mobius10.math.uwaterloo.ca (Warren Stevens)
Subject: Need access to array index in ctor
Organization: University of Waterloo
Date: Fri, 22 Jan 1993 22:40:44 GMT

I am creating a class, called block, that needs to know it's index in a
constructor if it is created as part of an array.  For instance,

	House	block[512];

would call block::block() 512 times.  Each time the constructor is called, 
i need to know what the index being created is.

Is there some way to do this easily?

Thanks,

Warren
Newsgroups: comp.lang.c++
From: mahesh@elcaro1.ColumbiaSC.NCR.COM (Mahesh Zambani)
Subject: Re: Optimized C++ library
Reply-To: mahesh@elcaro1.columbiaSC.NCR.COM
Organization: NCR Corp., Columbia
Date: Fri, 22 Jan 93 14:16:15 GMT

In article <1jofijINNm8o@rs2.hrz.th-darmstadt.de>, schrod@iti.informatik.th-darmstadt.de (Joachim Schrod) writes:
|> In article <1jng9aINN39s@male.EBay.Sun.COM>, pauln@loopkill.EBay.Sun.COM (Paul Nguyen) writes:
|> > 
|> > We have an application that runs OK when all the libraries were compiled with the
|> > -g option.  But when the libraries were re-compiled with -O for optimization.  The
|> > application seems to crash randomly in one of the library.
|> > 
|> > Is it possible that compiling with -O uncovered a bug?
|> 
|> Yes, in the compiler. Might be that you use the CC of Sun? (0.5 :-)
|> 
|> --
|> Joachim

	I had the same problem on HP9000/700 and SCO V3.2. But I discovered 
that only few source files were problematic. By compiling these without
-O flag and compiling rest of the files with optimization, my application
( quite a big size ) worked correctly.
	Off course, this depends on how many man hours you are ready to spend
to save a few cpu (micro)seconds!! :-)

- Mahesh

-- 

Mahesh Zambani                                mahesh@elcaro1.ColumbiaSC.NCR.COM

NCR MCPD , Columbia,SC 29170                  hello: off #803-791-6915
						     res #803-750-1863
_____________________________________________________________________________
Newsgroups: comp.lang.c++
From: pjl@cs.uiuc.edu (Paul Lucas)
Subject: Re: Smalltalk -> C++
Organization: University of Illinois at Urbana-Champaign
Distribution: usa
Date: Wed, 27 Jan 1993 16:00:32 GMT

In <1993Jan27.001545.4289@MasPar.COM> linton@argosy.UUCP (Tom Linton) writes:

>Does anyone know of a reliable program which can
>convert Smalltalk to C++?

	I would think that it's impossible.  Smalltalk has things like
	class-instance variables and blocks which C++ doesn't.  You also
	have to write all the Smalltalk primitives yourself since
	there's no (non-machine) code to be converted; you'd also have to
	convert all (many?) of the packaged classes, which are copyrighted
	by their vendors.

	Also, things like numbers aren't objects in C++ and don't
	respond well to messages.

	Even if it were possible, the resulting code wouldn't be the way
	it would have been had it been written in C++ to begin with.
	(This is true of any language-to-language conversion, IMHO).  To
	do it properly still requires people.
-- 
	- Paul J. Lucas
	  AT&T Bell Laboratories
	  Naperville, IL
Newsgroups: comp.lang.c++
From: fasteddi@acca.nmsu.edu (FastEddie(Callahans))
Subject: Request: FTPsite with C/C++ files/documentation
Organization: New Mexico State University
X-Newsreader: TIN [version 1.1 PL8]
Date: Mon, 25 Jan 1993 00:43:47 GMT

Hello... I'm looking for an FTPsite with either C/C++ files or documentation...
I've just started to code, and am looking for examples to help me figure out    this language(s)...

   Any help would be appreciated....

   Stan 'Fast Eddie' Paszt.
:
Newsgroups: comp.lang.c++
From: cliveg@cix.compulink.co.uk (Clive Grace)
Subject: Books For Sale
Cc: cliveg@cix.compulink.co.uk
Reply-To: cliveg@cix.compulink.co.uk
Date: Tue, 26 Jan 1993 23:41:00 +0000

UK-based books clearout

I have the following books for sale. If you live in the UK and want any 
of these, please email me. Each book costs #10 (ten uk-sterling pounds), 
Postage and Packaging is calculated on an individual basis -- basically 
the more books you buy the cheaper it gets :-)


C/C++ Programming
================= 
Power Graphics Using Turbo C K. Weiskamp (et al)
Programming In Zortech C++ With Version 2 John M.Hughes        
Microsoft Quick C Programmer's Toolbox John Clark Craig        
Graphics Programming In Turbo C 2.0 Ben Ezzell 
Topics in C Programming (Revised Ed) Stephen G.Kochan/P.H.Wood 
C Programming - A complete guide to mastering the C language Augie 
Hansen
C        Pat McKay 



+-------------------------------------------------------------------+
|  ..    "When I grow up, I want to stop being a computer journalist|
| .OO.    and learn how to write."                                  |
| O/\O                                                              |
|  --                              Tanais - friend to all furkindred|
+-------------------------------------------------------------------+
|cliveg@cix.compulink.co.uk | Bisexual knitter of quality since 1992|
+-------------------------------------------------------------------+
From: pjcondi@ns.pacbell.com (Paul Condie)
Newsgroups: comp.lang.c++
Subject: Re: operator = with inheritance
Date: 26 Jan 93 17:55:30 GMT
Article-I.D.: PacBell.1993Jan26.175530.1382
Organization: Pacific * Bell
X-Newsreader: TIN [version 1.1 PL8]



What would be wrong with this implementation:


#include	<iostream.h>

class A
{
   public:
	A (int arg = 0){
		 a = arg; 
	}

	virtual A & operator = (const A & rhs) {
		a = rhs.a;
		return *this;
	}

   private:
	int a;
};


class B : public A
{
   public:
	B (int arg = 0) : A(arg) {
		 b = arg; 
	}

	A & operator = (const A & rhs) {
		A::operator = (rhs);

		// The following cast should be ok because we know
		// we have a B object because the virtual mechanism
		// has told us. right?

		b = ((B &)rhs).b;

		return *this;
	}

   private:
	int b;
};



main ()
{
	A * obj3 = new B (1);
	A * obj4 = new B;

	*obj4 = *obj3;			// works for pointer types

	B obj1 (2);
	B obj2;

	obj2 = obj1;			// works for object types
}
Newsgroups: comp.lang.c++