-
C++ question
Hi,
I am studying C++ now and I need sometimes a little help.
Who can explain to me how work calls in main
bar(*b);
bar(d);
baz(*b);
baz(d);
and why functions with reference as parameter work different from functions
with value in parameters?
Vic.
------------------------------------------
#include <iostream.h>
#include <string.h>
#include <stdio.h>
class Base
{
public :
virtual void foo()
{
cout<<"Base"<<endl;
}
};
class Derived : public Base
{
public :
virtual void foo()
{
cout<<"Derived"<<endl;
}
};
void bar(Base bb)
{
bb.foo();
}
void baz(Base & br)
{
br.foo();
}
int main(int argc, char *argv[])
{
Base * b=new Derived;
Derived d;
b->foo();
bar(*b);
bar(d);
baz(*b);
baz(d);
delete b;
return 0;
}
-
Re: C++ question
"Vic" <ax515@lafn.org> wrote:
>
>Hi,
> I am studying C++ now and I need sometimes a little help.
> Who can explain to me how work calls in main
> bar(*b);
> bar(d);
> baz(*b);
> baz(d);
> and why functions with reference as parameter work different from functions
>with value in parameters?
>Vic.
>------------------------------------------
>#include <iostream.h>
>#include <string.h>
>#include <stdio.h>
i am studying c++ sometime si have problems
is there any body who can help me writing programs
my email address is
abcpost@hotmail.com
>class Base
> {
> public :
> virtual void foo()
> {
> cout<<"Base"<<endl;
> }
> };
>
>class Derived : public Base
> {
> public :
> virtual void foo()
> {
> cout<<"Derived"<<endl;
> }
> };
> void bar(Base bb)
> {
> bb.foo();
> }
> void baz(Base & br)
> {
> br.foo();
> }
>
>
>int main(int argc, char *argv[])
>{
> Base * b=new Derived;
> Derived d;
> b->foo();
> bar(*b);
> bar(d);
> baz(*b);
> baz(d);
> delete b;
> return 0;
>}ax515@lafn.org
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|