From: Joseph M. Newcomer on
You never return the "definition" of a class. You return an object of a specific type.

int f(...)
{
return 3;
}

does not return the "definition of int" but returns a value, 3.

struct T { ... };

T f(...)
{
T ret;
ret.whatever = ...;
return ret;
}

This is not even C++; this has been possible in C for decades. In fact, the only variant
of C in which this was *not* possible was the horrible K&R dialect of the PDP-11 and other
machines of that era (they couldn't return a value larger than an 'int' and so we got
silly things llike functions that took pointers to a long when they should have returned
the long as a value!)
joe

On Fri, 25 Jun 2010 12:23:49 -0400, "RB" <NoMail(a)NoSpam> wrote:

> Ok, well all of this is enlightening given I did not even know one
>could return the definition of class and have it constructed on the stack.
> So a reference does help (for the reason you gave) even though it may
>be a small copy, that is interesting. But then I shouldn't have equated the
>stack ownership as any ramification since other items are sometimes on
>the stack also. A reference is a reference I guess, no matter where it references.
>Thanks for the reply, I don't have any current questions.
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: RB on
> ****
> You are not returning the "definition of a class", you are returning an object of that
>.......................
> Actually, it is a *lot* more complex than that, but it is all magic and the magic works.
> For example, you cannot pass a pointer (or reference) to a stack variable across thread
> boundaries. In fact, C++ is predicated on a single-thread model so cross-thread
> much-of-anything is outside the scope of the language. Be careful about this.
>*****

Yea I am still fooling around with it I have two projects on it now, the second one
I am looking at more stuff but too early to understand enough to ask any questions.

! However * on the first smaller project I have this question that I did not notice
earlier. Why am I getting this first chance exception on entry of the Catch
===========================
#include <iostream.h>
#include <iomanip>

class ClassNoObject
{
public:
ClassNoObject() {}
~ClassNoObject(){}

void ClsNoObjFunc()
{ cout << "Throw Or Return Temp object class printing? \n"; }
};

void GlobalFunc()
{
cout << "fixing to throw ClassDefinition? \n";
throw ClassNoObject();
}

void main(void)
{
try
{
GlobalFunc();
}
catch( ClassNoObject& E ) //<--kernel exception here
{
E.ClsNoObjFunc();
cout << "Caught throw in catch\n";
}
}
====exception oupt shown below==========
catch( ClassNoObject E ) <- point of first chance exception
{
E.ClsNoObjFunc();
cout << "Caught throw in catch\n";
}
First-chance exception in ES1b.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
The thread 0xE14 has exited with code 0 (0x0).
The thread 0x438 has exited with code 4198860 (0x4011CC).
The thread 0xD98 has exited with code 4198860 (0x4011CC).
\VC_6_Projects\Exps_&_Refs\ES1b\Debug\ES1b.exe' has exited with code 4198860 (0x4011CC).
===========================

From: RB on
> catch( ClassNoObject& E ) //<--kernel exception here
I left this in paste but the exception is the same whether it's
reference or copy, there is something else going on with
the app.

> catch( ClassNoObject E ) //<--kernel exception here

Other than seeing the kernel exception in the debugger output
window the apps runs and displays the following,

fixing to throw ClassDefinition
Throw Or Return Temp object class printing
Caught throw in catch
From: Joseph M. Newcomer on
There are lots of places where first-chance exceptions are thrown, for reasons that are
largely unknown and undocumented.

If they don't interfere with the execution, we have learned to ignore them.
joe

On Fri, 25 Jun 2010 15:14:52 -0400, "RB" <NoMail(a)NoSpam> wrote:

>> catch( ClassNoObject& E ) //<--kernel exception here
>I left this in paste but the exception is the same whether it's
>reference or copy, there is something else going on with
>the app.
>
>> catch( ClassNoObject E ) //<--kernel exception here
>
>Other than seeing the kernel exception in the debugger output
>window the apps runs and displays the following,
>
>fixing to throw ClassDefinition
>Throw Or Return Temp object class printing
>Caught throw in catch
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: RB on


> There are lots of places where first-chance exceptions are thrown,
> for reasons that are largely unknown and undocumented.
> If they don't interfere with the execution, we have learned to ignore
> them. joe

Oh well that is good to know, I can continue with my other
experiments then. Thanks again.