Qbasicnews.com
Suspicious pointer assignment - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Suspicious pointer assignment (/thread-9066.html)



Suspicious pointer assignment - wallace - 03-24-2006

Code:
TYPE two3tree
  root as two3node ptr
  size as integer
  depth as integer
  AddNode as Sub(value as integer)
END TYPE

SUB AddNode(value as integer)
  If this.root = 0 then
    this.root = NewTwo3Node(value)
  else
    dim p as Two3Node ptr
    p = this.root
  end if
  this.size = this.size + 1
END SUB

NewTwo3Node returns a Two3Node ptr but that like gives me an Implicit conversion warning and p = this.root gives me the suspicious pointer assignement warning. What's going on?


Suspicious pointer assignment - stylin - 03-24-2006

Is this a global variable? Looks like it should be a parameter. ie., there is no implicit this, reference or pointer. You'll have to pass the address - or reference - of an 'object' to it's 'member functions' manually.


Suspicious pointer assignment - DrV - 03-24-2006

Yeah, function pointers are the same as in C - not member functions of classes. Make sure you use Option Explicit to catch undeclared variables.


Suspicious pointer assignment - wallace - 03-24-2006

O, I thought this worked the same was as it did in C++. There is no way to access a subs invoking data type from within the sub?

ie:
Code:
DIM temp as two3tree
temp = NewTwo3Tree
temp.AddNode(6)

There is no way to access temp from inside the AddNode sub without passing having it be a parameter?


Suspicious pointer assignment - Anonymous - 03-24-2006

Correct, it must be a parameter. hopefully fb will move rapidly towards a move to a gcc frontend, which will give us oop and lead basic users once and for all into the promised land...


er.. sorry i got carried away there :o