problem with reference variable
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > problem with reference variable




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    problem with reference variable  
niraj.kumar.ait@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 12:53 PM


tParserSo is a object of Soloader when i print the value of  objectPtr
in the soloader function then it has the correct value but it doesnt
return anything to tPrs .In some cases in work but some times it doesnt
work . I m using g++ 3.2.2 version





tParserSo.CreateObject((void *)tPrs)


bool SoLoader::CreateObject(void* & objectPtr){
try{
objectPtr =  mCreate();

std::cout<<objectPtr<<std::endl;

return true;
}catch(bad_alloc& exBadAlloc){
return false;
}


TIA
niraj






[ Post a follow-up to this message ]



    Re: problem with reference variable  
phil_gg04@treefic.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 12:53 PM

niraj.kumar.ait@gmail.com wrote:
> tParserSo is a object of Soloader when i print the value of  objectPtr
> in the soloader function then it has the correct value but it doesnt
> return anything to tPrs .In some cases in work but some times it doesnt
> work . I m using g++ 3.2.2 version
>
> tParserSo.CreateObject((void *)tPrs)

What is the definition of tPrs?
Get rid of that cast.

Do you get warnings when you compile with -Wall ?

> bool SoLoader::CreateObject(void* & objectPtr){
>   try{
>      objectPtr =  mCreate();
>
>    std::cout<<objectPtr<<std::endl;
>
>     return true;
>  }catch(bad_alloc& exBadAlloc){
>    return false;
>   }


--Phil.






[ Post a follow-up to this message ]



    Re: problem with reference variable  
niraj.kumar.ait@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-05 07:48 AM


does it matter what is the type of  tPrs
because we r typcating it as a void pointer passing its reference
No warning






[ Post a follow-up to this message ]



    Re: problem with reference variable  
phil_gg04@treefic.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-05 12:48 PM

Niraj,

> tParserSo.CreateObject((void *)tPrs)
> bool SoLoader::CreateObject(void* & objectPtr){

I don't think this does what you think it does.  I think that the cast
creates a temporary of type void*, and that is passed to CreateObject.
The temporary is assigned to and then discarded.  But I could be wrong,
and I would have expected a warning if that were the case.

I repeat my original suggestion: get rid of the cast.  E.g.

void* p;
tParserSo.CreateObject(p);
cout << p << endl;

--Phil.

p.s. comp.lang.c++ might be a better place to ask.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:08 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register