Errors, bugs, questions - page 3095

 

There is a script

class X {};

void fTest(X &Obj) {return;}

void OnStart()
  {
   X obj;
   fTest(GetPointer(obj));                      //ОК
//fTest(&obj);         //Compile error: '&' - parameter passed as reference, variable expected   
  }

Question: if GetPointer(obj) is passed ok, why &obj fails?

Is this needed for something?

 

I want to clarify, just in case. Suppose there is a code like this:

ClassX *x=new ClassX;

//какой-то код

delete x;

//......много кода, прошло много времени

ClassY *y=new ClassY;

Print(x==y);            // может ли быть true?
Is it possible in principle that x equals y?
 
mktr8591 #:

I want to clarify, just in case. Suppose there is such a code:

Is it possible in principle that x equals y?

Theoretically, yes. Previously, the pointer unsetting showed a counter (you could see the number of all objects). Now it's random.

 
fxsaber #:

Theoretically, yes. Previously, the pointer printout showed a counter (you could see the number of all objects). Now it's random.

Maybe, but it's a bit small for random - I usually have seven digits.
 
mktr8591 # :

There is a script

Question: if GetPointer (obj) is passed ok, why does &obj fail?

Is it needed for something?

There is no need for GetPointer () here.

   fTest(obj);                       //ОК

 // Это для чего-то нужно? 
   X *objptr;
   objptr = &obj;  
 
Alain Verleyen #:

There is no need for a GetPointer () here.

Agreed. I just wonder why there is such a difference in behaviour.
 
mktr8591 #:

I want to clarify, just in case. Suppose there is such a code:

Is it possible in principle that x equals y?

No, impossible.

 
mktr8591 #:

I want to clarify, just in case. Suppose we have the following code:

Is it possible in principle that x will be equal to y?


I recommend that you don't use an autoranging pointer to a reference and do it explicitly, as shown in the code below (highlighted in red):

class A
  {
  };

void func(A &)
  {
  }

void OnStart(void)
  {
   A a;   
   A *pa=&a;

   func(* pa);
  }
 
Ilyas # :


I recommend that you don't autorate the pointer into a link and do it explicitly as shown in the code below (highlighted in red):

What has changed? Isn't it the same after all?
 

There's no question about the error, but it's backdated for some reason.

class X {};

template <typename T>
void fTest(T &Obj) {return;}

void OnStart()
  {
   X obj;
   fTest(GetPointer(obj));                      //'GetPointer' - parameter passed as reference, variable expected - ДВАЖДЫ!
  }