PASSING BY VALUE
// class declaration
class Foo {};
void PassByValue(Foo f, int n)
{
// Do something with f and n.
}
int main()
{
Foo foo;
int i = 1;
PassByValue(foo, i);
}
PASSING BY POINTER
class Foo
{
public:
int data[100];
};
void PassByPointer(Foo* f, int n)
{
// Do something with *f and n.
}
int main()
{
Foo foo;
int i = 0;
PassByPointer(&foo, i);
return 0;
}
PASSING BY REFERENCE
class Foo
{
public:
int data[100];
};
void PassByReference(Foo& f, int n)
{
// Do something with f and n.
}
int main()
{
Foo foo;
int i = 0;
PassByReference(foo, i);
return 0;
}
[source]
No comments:
Post a Comment
Note: only a member of this blog may post a comment.