C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing Dereferenced Pointer objects as arguments to functio

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
DIBUR
Guest





PostPosted: Thu Dec 16, 2004 1:42 pm    Post subject: Passing Dereferenced Pointer objects as arguments to functio Reply with quote



Hi!!
if I run the following code will there be a problem
class X{
//defined
};
class Y{
X* ptr;
public:
int test(const X &);
};

int Y::test(*ptr) {
//do something
}

I ran a similar code and compiler gives an error something like this:
in function int Y::test(const X& ) an object expected in the
argument!!!

I cannot understand that when i have dereferenced the pointer then the
code should run normally as when we pass objects to such functions

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Antoun Kanawati
Guest





PostPosted: Thu Dec 16, 2004 6:19 pm    Post subject: Re: Passing Dereferenced Pointer objects as arguments to fun Reply with quote



DIBUR wrote:
Quote:
Hi!!
if I run the following code will there be a problem
class X{
//defined
};
class Y{
X* ptr;
public:
int test(const X &);
};

int Y::test(*ptr) {
//do something
}

I ran a similar code and compiler gives an error something like this:
in function int Y::test(const X& ) an object expected in the
argument!!!

I cannot understand that when i have dereferenced the pointer then the
code should run normally as when we pass objects to such functions

I don't see the call. I see a definition of an undeclared member
function.

You should have written:

int Y::test(const X &) { /* do something */ }

Somewhere else, you could write:

Y p;
X *x = new X();
p.test(*x);

and that would realize your wish of dereferencing a pointer to pass
a reference.

--
A. Kanawati
[email]NO.antounk.SPAM (AT) comcast (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Andrew Koenig
Guest





PostPosted: Fri Dec 17, 2004 4:39 am    Post subject: Re: Passing Dereferenced Pointer objects as arguments to fun Reply with quote



"DIBUR" <nishant404 (AT) yahoo (DOT) com> wrote


Quote:
class X{
//defined
};
class Y{
X* ptr;
public:
int test(const X &);
};

int Y::test(*ptr) {
//do something
}

I ran a similar code and compiler gives an error something like this:
in function int Y::test(const X& ) an object expected in the
argument!!!

This code should not compile, because the declaration and definition of
Y::test have different signatures (not to mention that the definition has a
syntax error).

Once you post syntactically correct code, we can talk about what it means.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.