Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » differences in returns between pointer and reference
differences in returns between pointer and reference [message #56940] Sun, 02 May 2021 17:18 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

as a novice in c ++, put down some interesting returns of variable values between "pointer" and "reference" alternating.

if possible, I ask that the experts express about the only one that does not return value is the struct abc!


struct abc{
     String b;
   public:
       abc( String& xx){
         b=xx;    
       }
       void fecha(){
          b="retornado";   // this not return: reference constructor is address 
       }
       ~abc(){};
};

struct de{
     String* b;
   public:
       de( String* xx){
         b=xx;    
       }
       void fecha(){
          *b="retornado";  // this return: reference constructor is pointer
       }
       ~de(){};
};


void rotina1( String &s )
{
   s="123";	
}
void rotina2( String *s )
{
   *s="yyy";	
}

CONSOLE_APP_MAIN   
{

   String st="abc";
   
   rotina1(st);
   
   Cout() << "after rotina1:  " << st << EOL;  
   
   String* a = &st;
   
   rotina2(a);
   
   Cout() << "after rotina2: "<< *a << EOL;  
   
   abc c(*a);
   c.fecha();
   c.~abc();
   
   Cout() << "after struct abc: "<< *a << EOL;  

   de d(a);
   d.fecha();
   d.~de();
   
   Cout() << "after struct de: "<< *a << EOL;  
	
}


 
Read Message
Read Message
Read Message
Previous Topic: gdb debug is not working in theide on macos catalina
Next Topic: static
Goto Forum:
  


Current Time: Mon Apr 29 19:40:44 CEST 2024

Total time taken to generate the page: 0.02810 seconds