in C:
struct Thing
{
int data;
};
int doSomething( Thing* aThing );
Thing object;
// Now call the function for the data.
doSomething( &object );
in C++:
class Thing
{
int data;
// The scope of variables/data in C++ is, by default, private
// whereas in structs it is public. This is actually the ONLY
// difference between structs and classes in C++.
public:
int doSomething( void );
};
Thing object;
// Now call the function for the object.
object.doSomething();
Behind the scenes the compiler is actually passing the address of object as a
parameter to the doSomething function. The cost of the function call is the same in
this example. In C++ you can inline the function and eliminate the cost of the
actual function call yet still retain full type safety enforcement by the compiler.
regards,
Ben Scherrey
Andrea Arcangeli wrote:
> On Wed, 6 Jan 1999, Alan Cox wrote:
>
> > the compiler but does seem to be at least fractionally the language - its very
> > hard to figure out in C++ when you can avoid passing 'self' around for
> > example.
>
> What does it mean "passing self around"?
>
> Andrea Arcangeli
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/