HDTenEightyP/NetNews huggingface dataset:
From:  alex@erma.msk.su (alex)
Subject: Re: defining cast operators outside classes
Date: Tue, 8 Sep 1992 11:18:45 GMT
Reply-To: alex@erma.msk.su
Organization: JV ERMA International

tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
>   Apparently, it is impossible to define a conversion operator for a
>   class without making the conversion operator a member function.
>
>   It would be very useful to be able to define something like the
>   following without having to modify either class MyMatrix or class
>   TheirMatrix:
>
>           operator MyMatrix(TheirMatrix &m) {
>                   ...
>           }
>
>   Why was this seemingly arbitrary restriction made? Can it be
>   eliminated in the next version of C++?
>
>                                           Thomas.
>

        Conversion operators were invented to allow implicit typecasting
for user defined data types (i.e. classes). Since it is impossible to cast
"nothing", conversion function should have an argument - the object that is
to be typecasted. Making conversion operators to be member functions forces
this requirement to be always met. Otherwise one could write something like:

        operator MyMatrix() {
                ...
        }

------------------------------------------------------------------------
Alexander Pavlov                      ERMA International, Moscow, Russia


Newsgroups: comp.lang.c++
From: J.March@lut.ac.uk
Subject: Novice question
Reply-To: J.March@lut.ac.uk (Jon March)
Organization: Loughborough University, UK.
Date: Sat, 5 Sep 92 03:02:24 GMT

I'm getting quite few "warning: assignment to this (anachronism)" messages
from my compiler.  I do actually want to do this, so how do I let my
compiler know that I *really* mean it.

By declaring "this" to be a *const, is "this" effectively being passed by 
reference?  Thinking of the semantics here.

Jon March
From: ipser@solomon.technet.sg (Ed Ipser)
Newsgroups: comp.windows.ms.programmer,comp.lang.c++
Subject: BC++/MS Windows:  How Do You Call Anonymous Functions?
Summary: How Do You Call Anonymous Functions?
Date: 7 Sep 92 04:20:33 GMT
Organization: TECHNET, Singapore



How Do You Call Anonymous Functions?

Here is the problem: I want to write an interpreter under Borland C++
and MS Windows and I need to be able to call arbitrary functions from
within the interpreter such as Windows API functions as well as
user-defined functions from DLLs. Of course, normal function pointers
will not work for two reasons: first, they would require a function
type for every type of function and, worse, the types of functions are
not known when the interpreter is compiled since the user can define
his own.

I know a solution exists because many applications have this capability.

Let me phrase the problem more precisely:

I want to write two functions:

  function_type* get_function (
    char* dll_file, char* name) ;

the get_function function would return a far pointer to a function from the
name of the DLL containing the function and the name of the function.

and:

  void apply_function (
    function_type* function,
    int parameter_size, void* parameters,
    int result_size, void* result) ;

which would push the parameters and result on the stack, call the function, and then
copy the result into the result parameter.

for example, the following would call the Windows max function:

void dummy ()
{
  struct
  {
    int x ;
    int y ;
  } xy ;
  int max ;

  apply_function(get_function("windows","max"),4,&xy,2,&max) ;
  cout << max ;
} ;



The next question, of course, is how do you do this with data members and
member functions of classes? How do you find the virtual tables?
From: coller@alnitak.usc.edu (Lee D. Coller)
Newsgroups: comp.lang.c++
Subject: Avoiding returning references to Temporaries
Date: 6 Sep 1992 12:02:21 -0700
Organization: University of Southern California, Los Angeles, CA
Distribution: world
NNTP-Posting-Host: alnitak.usc.edu

The following classes represent I problem I have encountered.

class A {
public:
    void func() = 0;
};

class B : public A {
private:
    int _i;
public:
    void func();
};

class C: public B {
private:
    double _d;
public:
    void func();
};

class D {
private:
    /* some information from which to construct a B or C */
public:
    A getA() const;        // ideally
};

The idea is that the member function D::getA() would be able to construct a
B or C and return it to the caller as an A.  Because of the semantics, most
likely D::getA() will have to create a temporary, so just returning a
reference to some pre-existing B or C will not work.

Of course returning an A won't work because the pertinent information in
either B or C is lost, and won't even compile because A is abstract.

The simple solution is to allocate the B or C off the heap, with the caller
of D::getA() responsible for deleting it.  I don't like this solution
because it is inelegant and the subclass of B or C is usually not kept
around outside the scope of the caller.

The obvious solution is to use a class which can be Garbage Collected, but
C++ currently has no such thing.

The best solution I could come up with is to create another class to handle
managing a pointer to A such as the following.

class AHandler {
private:
    A* _a;
public:
    AHandler(A* a) { _a = a; a->ref(); }    // use reference counting GC
    ~AHandler(A* a) { _a->unref(); }

    AHandler operator=(const AHandler &a) 
	{ a._a->ref(); _a->unref(); _a = a._a; }

    A* operator->() const { return _a; }
    operator a&() const { return *_a; }
    a& operator*() const { return *_a; }
};

Then the member function getA() would return an AHandler, that it created
using a B or C allocated off the heap.  Class A would implement reference
counting (and probably a copy member that return an A*), and AHandler
would take care of management of the A*.  The operators would allow AHandler
to be treated like an A* or an A, depending on the context (in the actual
implementation, A includes some overloaded operators for comparison, thus
the operator a&() conversion).

My question is, I would like to be able to do this without having A handle
reference counting.  Can anyone think of a good method?  Am I overlooking
some simple, elegant solution?  Also, is this what is referred to as a
"Smart pointer class?"

Thanks,
-- 
-----------------------------------------------------------------
Lee D. Coller (coller@alnitak.usc.edu)		+1 (310) 379-0844
USC Behavioral Technology Labs, 250 N. Harbor Dr. Ste 309
Redondo Beach, California, 90277
Newsgroups: comp.lang.c++
From: skdutta@ucs.att.com (Saumen Dutta)
Subject: C++ product list - Information request
Organization: AT&T Universal Card Services, Jacksonville FL
Date: Wed, 9 Sep 1992 15:11:10 GMT

I am maintaining a list of C++ products ( Compilers, Libraries and Tools)
for this newsgroup. In addition to the product descriptions this list provides
User's feedback on the products. Most of this list is made out of information 
obtained from readers of this group. 

I know that there are lot of products out there which is not yet included in 
this list. I would appreciate if you send some information to make this list 
more useful.

For new products, please send information in the proper format ( the
format can be obtained from the previous C++ product list posted to this
group. Let me know if you have any problems getting this). If possible 
please send the information in plain ascii without any indentation. 

You can also send your feedback on the C++ products you normally use.
The User feedback should not be more than half a page. For User feedback 
let me know if you do not want your name to be included with your comments.

If you send any information regarding this in the past two months, I
would appreciate if you send it again.

Thanks
skdutta
From: cee1@ra.msstate.edu (Charles Evans)
Newsgroups: comp.lang.c++
Subject: Problems with int as enum
Date: 13 Sep 92 22:26:23 GMT
Article-I.D.: ra.1992Sep13.222623.21562
Organization: Mississippi State University

BC++ 2.0 :

(Trying to learn some C++ here in my spare time.. well the first real program
in book I am using, "C++ for C Programmers", has this  [edited for brevity])

#include <stream.h>
#include <stdlib.h>  		// optional

int random(void);

enum suit { clubs, diamonds, hearts, spades };

struct card { suit s; int pips };

...

void init_deck(card d[])
{
	for (int i = 0; i < 52; ++i)
	{
		d[i].s = (i / 13);   // enum as int ? -- WARNING #1
		d[i].pips = 1 + i % 13;
	}
}
void shuffle(card d[])
{
	for (int i = 0; i < 52; ++i)
	{
		int k = random() % 52 	// choose a random card
		card t = d[i];		// swap two cards ERROR #2, #3
		d[i] = d[k];
		d[k] = t;		// ERROR #4
	}
}

....

int main(void)
{
	card deck[52];

	init_deck(deck);
	pr_deck(deck);
	shuffle(deck);
	pr_deck(deck);
	return(0);
}

-----

WARNING #1 : Assigning int to suit in function init_deck(card far*)
ERROR #2 : Undefined symbol 'card' in function shuffle(card far*)
ERROR #3 : Undefined symbol 't' in function shuffle(card far*)
ERROR #4 : Undefined symbol 't' in function shuffle(card far*)

---

So whats the problem with swapping 'cards'? cant you define a 'card t'??
Help. No clue.
No sleep.

chuck



-- 
+--------------------+-----------------------+------------------------+
|  Charles E. Evans  |  cee1@ra.msstate.edu  |  All things are green  |
|    iDLE CHATTEr    |  cee1@MSSTATE.BITNET  |  unless they are not.  |
+--------------------+-----------------------+------------------------+
From: rmartin@thor.Rational.COM (Bob Martin)
Newsgroups: comp.lang.c++
Subject: Re: Destructors and exit()
Date: 5 Sep 92 17:38:32 GMT

rmartin@thor.Rational.COM (Bob Martin) writes:

|rgp@mpd.tandem.com (Ramon Pantin) writes:

||IMHO, it would be incorrect for a compiler to "know" anything about
||exit (exit is part of the C library, not part of the language, "exit"
||is not a keyword).  A call to the exit function has never triggered
||destructions of automatic objects and should never do.  The block where
||the object was constructed is not being exited when the exit function
||is called so it is incorrect to destroy the object. 

|In general I agree with this. But I have seen compilers which have
|taken such liberties.  

I was running around the track at the health club today.  About two
miles into my run, the following thought occured to me: 

A reasonable implementation of exit would be:

void exit(int status)
{
  throw(exitException(status));
}

Presumably this exception would be caught by the preamble code which
calls 'main'.  Such an implementation of 'exit' *would* cause the
destructors of all currently existing auto variables to be called.

Now, 'exit' is not currently defined this way, and I don't know if any
of the compiler manufacturers are even considering it.  But the above
implementation is defensible, and perhaps even superior to the current
implementation.

Just a thought.


--
Robert Martin                        Training courses offered in:
R. C. M. Consulting                       Object Oriented Analysis
2080 Cranbrook Rd.                        Object Oriented Design
Green Oaks, Il 60048 (708) 918-1004       C++
Newsgroups: comp.lang.c++
From: gillies@noao.edu (Kim Gillies)
Subject: Anybody using ET++ on Suns?
Keywords: Help Bus Error
Organization: National Optical Astronomy Observatories, Tucson, AZ, USA
Date: Sat, 12 Sep 1992 00:46:20 GMT

I'd like to make contact with anyone who has a version of ET++ running on
a Sun Sparc.  I have some problem that causes the test "hello" application
to "bus error" very soon after starting that I can't seem to solve.  Any 
version of ET++ is ok.  But I'm currently using ET++ 3.0-alpha, 
Sun OS 4.1.3, and the cfront that comes with ObjectCenter (2.1).
Any information is appreciated.  Mail me at gillies@noao.edu.

Also, is there an ET++ mailing list? 

  Kim Gillies
  National Optical Astronomy Observatory
  gillies@noao.edu
-- 
Kim Gillies, National Optical Astronomy Observatories, Tucson, Arizona USA
Internet: gillies@noao.edu  phone: 1 602 325 9246
From: mhr@hitkw18.pki-nbg.philips.de (Muharem Hrnjadovic)
Newsgroups: comp.lang.c++
Subject: Re: Why no source control in Borland
Date: 11 Sep 92 07:24:44 GMT

parry@yoyo.cc.monash.edu.au (Tom J Parry) writes:

>It strikes me as starnge that given the current size of the Borland C++ 3.1
>compiler package, that there is no source control system.

I don't think "comp.lang.c++" is the right newsgroup to discuss 
features you'd like to have incorporated in Borlands C++ compiler. 

Regards,


  -- M. Hrnjad.



------------------------------------------------------------------------------
       Muharem Hrnjadovic * Elsnerstr. 2 * 8500 Nuernberg 80 * Germany
                         mhr@pki-nbg.philips.de       
------------------------------------------------------------------------------
Organisation: European Space Operation Centre (E.S.O.C)
Date: Saturday, 12 Sep 1992 15:05:12 CET
From: Karl Keyte <KKEYTE@ESOC.BITNET>
Newsgroups: comp.lang.c++
Subject: Re: Answers on a postcard...
 <92255.112151KKEYTE@ESOC.BITNET> <1992Sep11.174716.3699@taumet.com>

>>The implication of what you say is that it is not possible to overload
>>operators maintaining the correct functionality of the operator.  This
>>indeed means that precedence in overloaded operators cannot be maintained
>>if all operands are simply passed as arguments to the function implementing
>>the operator functionality and evaluated in a language independent order.
>>Imagine commonly used "chain" operators such as && and ::.
>
>The only other overloadable operator which imposes order of evaluation
>is the comma.  Originally it was not overloadable, since there seemed
>to be no good reason to allow it.  It looks like we have found a
>good reason to disallow it, namely that the implied order of
>evaluation no longer holds.  (Too bad it is so hard to stuff the
>genie back into the bottle.)
>

I accept what you're saying but my point is this...  In overloading, for
example, the '+' operator for one of my own classes, I would try to provide
functionality which fits with the usual understanding of the operator.  In
providing '+' for "strings" I would hope to offer concatenation rather than
truncation with the '+' operator.  That works quite well.  If I require
something which is unrelated to any operator I would rather not overload
but provide a member function.  This means, when I overload an operator
it is because I want to perform some function which is similar (in concept)
to the original operator.  I also want the user (programmer) to be able to
use the operator in the usual fashion.

To do what I have just described with the comma-operator in C++ is not
possible.  Of course I can overload it to do something completely unrelated
to what one understands of the operator, but to do something "special" and
leave its order of evaluation the same as the operator is not possible.
I feel that this is an oversight rather than expected behaviour.  I can't
find any reference to the specifics of overloading the comma-operator in
any of the reference works, other than that it is possible to overload.

You mention that there seems no sensible reason to allow its overloading.  I
see no sensible reason to "disallow" it unless the order of evaluation
problem cannot be rectified, which of course it could.  At present I feel
the situation is not clear enough in this area.

Karl
Newsgroups: comp.lang.c++
From: kanze@us-es.sel.de (James Kanze)
Subject: Re: constructor call during initialization of same class
Organization: SEL-Alcatel LTS Dept. US/ES
Date: Fri, 28 Aug 92 14:13:27 GMT

I'm reposting the following, since I notice that I forgot to correct the distribution
in the initial post.  (We default to a local distribution here.)

In article <1992Aug23.154530.1131@taumet.com>, steve@taumet.com (Steve Clamage) writes:
|> casadei@verona.mit.edu (Stefano Casadei) writes:
|> 
|> >Is it possible to define a class constructor which invokes another
|> >constructor of the same class during the initialization phase (i.e. between
|> >the : and the body) ? If not, why is such a simple feature not implemented
|> >in the language ?

     [...]

|> I am guessing that you want to share some code by having several
|> constructors call a "basic" constructor.  You can't do that with
|> a construcutor.  You can write an initialization function which all
|> constructors call.  This is equivalent to what I think you want:
|> 	class foo {
|> 	public:
|> 	    foo();
|> 	    foo(int);
|> 	    foo(char*);
|> 	private:
|> 	    init();
|> 	}
|> 	foo::foo() { ... init(); ... }
|> 	foo::foo(int i) { ... init(); ... }
|> 	foo::foo(char* p) { ... init(); ... }

Actually, I think you *can* call a constructor (for the same object)
within a constructor.  If not, what does the following code do:

    foo::foo(int i) { ... ; new (this) foo ; ... }

On the other hand, I don't think you really want to.  To begin with,
the syntax is, to say the least , unpleasant.  And what happens if
foo is a derived class: the constructor for the base class gets called
twice, without an intervening destructor.  That could lead to some
unpleasantness too.
--
James Kanze                       GABI Software, Sarl.
email: kanze@us-es.sel.de         8 rue du Faisan
                                  67000 Strasbourg
                                  France
Newsgroups: comp.lang.c++
From: brady@kanga.aero.org (Wayne Brady)
Subject: Safe Arithmetic Operations
Keywords: error,type
Organization: The Aerospace Corporation; El Segundo, CA
Date: Thu, 10 Sep 1992 21:06:09 GMT

C++ has no error handling for overflow, underflow, divide 
by zero, etc.  We are considering writing safe types to 
replace the built in int, unsigned int, float, double, etc.
We would like to trap the errors and provide information
to the user about the location of the error.

Has anyone already done this?

If you email answers to me, I will post a summary.

	

Xref: sparky comp.lang.c++:13501 comp.windows.open-look:3794 alt.toolkits.xview:855
From: dlb@unixland.natick.ma.us (David L. Briggs)
Subject: pointer to member function.
Organization: Unixland Public Access Unix & Think_Tank BBS
Date: Sat, 5 Sep 1992 01:54:22 GMT

	A simple question.  If you have a class that has several functions
with the same name that are overloaded, how can you take the address of one
of these function?
Newsgroups: comp.lang.c++
From: ashok@cellnet.com (Ashok Bakthavathsalam)
Subject: Looking for a semaphore class specification/implementation 
Organization: Domestic Automation Company
Distribution: usa
Date: Thu, 10 Sep 1992 17:22:06 GMT

The subject says it all...

 % ashok
From: frank@Cookie.secapl.com (Frank Adams)
Subject: Re: template typedef
Date: Wed, 09 Sep 1992 21:22:21 GMT
Organization: Security APL, Inc.

In article <1992Aug27.132128.10015@ericsson.se> jonas@falcon.ericsson.se (Jonas Nygren) writes:
>I wonder if the following construct for templates and typedefs ever
>have been considered. Would it be possible to add this to the
>language.
>
>template<class S, class T> X {};
>
>template<class T> typedef X<Y,T> xy;
>
>xy<Z> xyz; // equiv to X<Y,Z>

I have also wanted this.  Note that xy<Z> must be the same type as X<Y,Z>,
not just a subclass.
From: jdc@naucse.cse.nau.edu (John Campbell)
Newsgroups: comp.lang.c++
Subject: dynamic arrays of objects
Keywords: arrays, dynamic
Date: 14 Sep 92 21:20:48 GMT
Organization: Northern Arizona University, Flagstaff AZ

Well, I'm about stumped.  As a struggling new c++ programmer I can only
guess that I'm having a paradigm shift problem.  

What I want to do is increase an array of pointers to objects so that 
I can write an ``append'' member function.  I've read question 35 of 
the FAQ and so I know that realloc is not a good thing.  However, I 
want to simply increase the size of the array of pointers and (as a
C programmer) it seems to me that this should be easy to do.

Here's two examples of the problem I'm facing--they're the same in
my mind.

class Timed_list:                          class row_vector:
   int count;                                 int dimen;
   Timed_elem *array;                         Fraction array;
   . . .                                   . . .

I want to add a new Timed_elem to Timed_list or a new Fraction to row_vector.  
I can easily increment count or dimen, and use new to build a new Fraction 
or a new Timed_elem, but how in the world do I ensure that there is space 
in array for the next element (array[count] = Timed_elem (item))?
I need to make ``array'' grow at this point.

I realize c++ has a fine mechanism for allocating memory for arrays
if you know the size or can assume a maximum size ahead of time.  However,
I would rather dynamically allocate the memory and reallocate it at
various stages as my arrays grow.  Anything less, in my mind, is a step
backward--back to those FORTRAN days when you had to recompile to overcome
arbitrary array limits in the code.

Is this normally done by "renewing" the array itself and replacing it
with array[count+1] in the append routine?  Otherwise, in Scott Meyers'
book (Effective C++) he shows using a linked list to solve a problem 
similiar to this.  I could implment a linked list, but it seems nasty--do 
I next have to overload the array operator ``[]'' simply to add a slot 
to an otherwise fully functional array.  And how do I effeciently traverse 
a linked list to reach the "i'th" element, anyway?

What am I missing? 

I apologize if this has been hashed out here recently.  I read the FAQ
as carefully as possible and couldn't find a definitive answer there...
As I said, I'm probably frustrated due to old methodology from a long
time ago in a paradigm far, far away.
-- 
	John Campbell               jdc@naucse.cse.nau.edu
                                    JDC@NAUVAX.UCC.NAU.EDU
From: rmartin@thor.Rational.COM (Bob Martin)
Newsgroups: comp.lang.c++
Subject: Re: Novice question
Date: 8 Sep 92 23:13:27 GMT

J.March@lut.ac.uk writes:

|I'm getting quite few "warning: assignment to this (anachronism)" messages
|from my compiler.  I do actually want to do this, so how do I let my
|compiler know that I *really* mean it.

I am not sure that you do.  Assigning to 'this' is an old facility of
the language which will disappear in the next release or so.  It used
to be used as a way to allow a constructor to allocate it's own
memory.  It was made an anachonism when operator new was added to the
language.

So, do you really mean it?  If you do, then you must live with the
warning, and you must live with the fact that later compilers will not
support it.

|By declaring "this" to be a *const, is "this" effectively being passed by 
|reference?  Thinking of the semantics here.

In C++ terms, 'this' is a pointer.  In more general terms, you could
say that 'this' was "self" passed by reference....  6 of one...


|Jon March
--
Robert Martin                        Training courses offered in:
R. C. M. Consulting                       Object Oriented Analysis
2080 Cranbrook Rd.                        Object Oriented Design
Green Oaks, Il 60048 (708) 918-1004       C++
Newsgroups: comp.lang.c++