473,378 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Pointers to Pointers?

i need to know if i can have a pointer to a pointer in VB.NET

given

Class CClass
'declarations
End Class

and then

Sub MySub()
Dim MyClass as CClass
End Sub

MyClass is a 'pointer' to a CClass object.
what i need is a pointer to a pointer...
my problem is that if i do this

Dim MyClassA as CClass
Dim MyClassB as CClass

MyClassA = Object1
MyClassB = MyClassA

it simply copies the address that MyClassA refers to, to MyClassB
i want MyClassB to point to the address of MyClassA if possible

this way whenever i repoint MyClassA at something new, MyClassB will point
at the same new object. the way it is above, if i reasign MyClassA to a new
object, MyClassB will still point at the first object. this is really easy to
do in C/C++...

heres something like what it could look like:

Dim MyClassA as CClass
Dim MyClassB as CClassPointer

MyClassA = Object1
MyClassB = MyClassA 'MyClassB points at MyClassA, instead of pointing at
what MyClassA points at

MyClassA = Object2 'now both MyClassA, and MyClassB point at the new object
Nov 21 '05 #1
10 1035
Dave,

It makes me always curious, when I started with programming I "needed"
pointers to get values from memory. (It was really the hard places in
memory, not a virtual place given by the OS).

I can assure you that it is long ago, and I am happy that those days are
behind me, because it was as description what the program was doing nothing.

Why want people still make application programs in this style from far back
in the previous century?

Cor
Nov 21 '05 #2
i dont know what you mean, pointers are far from obsolete. what i describe is
easily doable in C/C++.

i am simply using the C/C++ word 'pointer'. in VB:

Dim ClassReference As MyClass

is a 'pointer' to a class.

IIRC in C/C++ it looks like

MyClass * ClassPointer;

and a Pointer to a Pointer would be easily done with

MyClass ** ClassPointerPointer;

just wondering if this is possible in VB too... or if theres a way to get a
similar effect.

"Cor Ligthert [MVP]" wrote:
Dave,

It makes me always curious, when I started with programming I "needed"
pointers to get values from memory. (It was really the hard places in
memory, not a virtual place given by the OS).

I can assure you that it is long ago, and I am happy that those days are
behind me, because it was as description what the program was doing nothing.

Why want people still make application programs in this style from far back
in the previous century?

Cor

Nov 21 '05 #3
Dave,

Back in 1830 people where riding on a horse from New York to San Francisco,
they had only one other choise and that was sailing around Cape Horn.

Probably is both still possible. However I have not the idea that it is the
fastest and the most comfortable way to do that.

It was for me not the question if it is possible, I was curious why you
would do it this way. (Going on a horse, instead of easier and more
comfortable way).

Cor
Nov 21 '05 #4

"Dave Cousineau ( Sahuagin )" <Da*******************@discussions.microsoft.com > wrote
i need to know if i can have a pointer to a pointer in VB.NET

given

Class CClass
End Class

Sub MySub()
Dim MyClass as CClass
End Sub

MyClass is a 'pointer' to a CClass object.


Bzzzzzzt! MyClass is a reference to an object not a 'pointer'.
There is a Pointer type in the System.Reflection namespace,
(for unmanaged code) but they are not for use in VB....

LFS

Nov 21 '05 #5
eh ok, i was using the term loosly...

what i am looking for then is instead of a reference to an object, a
reference to a reference

ill explain what im trying to do.

this is for a 2D game graphics engine.
basically i want a list of specific objects under settings that the game
uses, and that the user is free to reassign.

ie:

Shadow Sprite
Fire Sprite
Game Over Sound Effect

the user will choose a particular sprite or sound effect from the sprite and
sound effect lists for each item under this settings screen. then the main
part of the game can simply use 'Game Over Sound Effect' at the appropriate
time and

the problem is that i cant save any of these settings values in any other
object, because if i do it doesnt refer to the settings object, it will refer
to whatever sprite/sound object the user selected, and then if he changes it,
it wont have an effect... i want to be able to have a reference to these
object reference variables, if possible...

"Larry Serflaten" wrote:

"Dave Cousineau ( Sahuagin )" <Da*******************@discussions.microsoft.com > wrote
i need to know if i can have a pointer to a pointer in VB.NET

given

Class CClass
End Class

Sub MySub()
Dim MyClass as CClass
End Sub

MyClass is a 'pointer' to a CClass object.


Bzzzzzzt! MyClass is a reference to an object not a 'pointer'.
There is a Pointer type in the System.Reflection namespace,
(for unmanaged code) but they are not for use in VB....

LFS

Nov 21 '05 #6

"Dave Cousineau ( Sahuagin )" <Da*******************@discussions.microsoft.com > wrote
this is for a 2D game graphics engine.
basically i want a list of specific objects under settings that the game
uses, and that the user is free to reassign.

ie:

Shadow Sprite
Fire Sprite
Game Over Sound Effect

the user will choose a particular sprite or sound effect from the sprite and
sound effect lists for each item under this settings screen. then the main
part of the game can simply use 'Game Over Sound Effect' at the appropriate
time and

the problem is that i cant save any of these settings values in any other
object, because if i do it doesnt refer to the settings object, it will refer
to whatever sprite/sound object the user selected, and then if he changes it,
it wont have an effect... i want to be able to have a reference to these
object reference variables, if possible...

You lost me at the part about 'then if he changes it'.

He selected the effect in the first place, and you are using that, so you have
a means to use what the user selects. If he selects another effect he has to
be on the settings screen as before, does ne not? Where can he make a change
in what he selects other than on the settings screen (which you are already
using)?

If it were me, I'd create a settings class and let the user alter its property
values. Any code that needs to use one of the values gets it from the
settings class. If the user changes a value, it goes into effect on next use
(because the code calls the same property he just changed....)

I just don't see a need for such indirection for user options. As long as
you use the same property the users sets, how are you going to get out
of sync?

LFS
Nov 21 '05 #7
heres an example:

all physical game objects will have a 'shadow sprite' object reference.
instead of the user (the user of the game design software not the game
itself) going to each new game object he creates and selecting a sprite for
the shadow there, he just goes into a settings form, and theres a setting for
'shadow sprite'. all game objects would now have a 'shadow sprite' member
that is a reference to a reference, which refers to the reference he selected
under the settings form.

is this taboo or something? its a simple question that seems like it could
easily be answered by just saying 'no there isnt'.

"Larry Serflaten" wrote:

"Dave Cousineau ( Sahuagin )" <Da*******************@discussions.microsoft.com > wrote
this is for a 2D game graphics engine.
basically i want a list of specific objects under settings that the game
uses, and that the user is free to reassign.

ie:

Shadow Sprite
Fire Sprite
Game Over Sound Effect

the user will choose a particular sprite or sound effect from the sprite and
sound effect lists for each item under this settings screen. then the main
part of the game can simply use 'Game Over Sound Effect' at the appropriate
time and

the problem is that i cant save any of these settings values in any other
object, because if i do it doesnt refer to the settings object, it will refer
to whatever sprite/sound object the user selected, and then if he changes it,
it wont have an effect... i want to be able to have a reference to these
object reference variables, if possible...

You lost me at the part about 'then if he changes it'.

He selected the effect in the first place, and you are using that, so you have
a means to use what the user selects. If he selects another effect he has to
be on the settings screen as before, does ne not? Where can he make a change
in what he selects other than on the settings screen (which you are already
using)?

If it were me, I'd create a settings class and let the user alter its property
values. Any code that needs to use one of the values gets it from the
settings class. If the user changes a value, it goes into effect on next use
(because the code calls the same property he just changed....)

I just don't see a need for such indirection for user options. As long as
you use the same property the users sets, how are you going to get out
of sync?

LFS

Nov 21 '05 #8
Dave Cousineau ( Sahuagin ) schrieb:
heres an example:

all physical game objects will have a 'shadow sprite' object reference.
instead of the user (the user of the game design software not the game
itself) going to each new game object he creates and selecting a sprite for
the shadow there, he just goes into a settings form, and theres a setting for
'shadow sprite'. all game objects would now have a 'shadow sprite' member
that is a reference to a reference, which refers to the reference he selected
under the settings form.

is this taboo or something? its a simple question that seems like it could
easily be answered by just saying 'no there isnt'.


pseudo code:

class settings
public shadowsprite
end class
class gameobject
dim settings as settings
end class

Something like this?

Armin
Nov 21 '05 #9
Pointers aren't allowed in VB. There are ways to access memory locations
directly, however, using unsafe code and special methods. These aren't
needed very often, however. The only time I've ever had use for them in VB
is when the API calls are just way too slow (like when manipulating
graphics).

What you want sounds more like what Larry proposed - a class that defines
your property values. If you are really against this idea, you can store
the properties as objects in a HashTable or SortedList or something:

Class ShadowSprite
' define properties/methods, etc.
End Class

Class GameObject
Public Settings As New HashTable
End Class

Dim GO As New GameObject
Dim Sp As New ShadowSprite

GO.Settings.Add("ShadowSprite", Sp)

It sounds like you might want to serialize this, so you'll want to keep that
in mind when you create your classes.

"Dave Cousineau ( Sahuagin )"
<Da*******************@discussions.microsoft.com > wrote in message
news:64**********************************@microsof t.com...
heres an example:

all physical game objects will have a 'shadow sprite' object reference.
instead of the user (the user of the game design software not the game
itself) going to each new game object he creates and selecting a sprite
for
the shadow there, he just goes into a settings form, and theres a setting
for
'shadow sprite'. all game objects would now have a 'shadow sprite' member
that is a reference to a reference, which refers to the reference he
selected
under the settings form.

is this taboo or something? its a simple question that seems like it could
easily be answered by just saying 'no there isnt'.

"Larry Serflaten" wrote:

"Dave Cousineau ( Sahuagin )"
<Da*******************@discussions.microsoft.com > wrote
> this is for a 2D game graphics engine.
> basically i want a list of specific objects under settings that the
> game
> uses, and that the user is free to reassign.
>
> ie:
>
> Shadow Sprite
> Fire Sprite
> Game Over Sound Effect
>
> the user will choose a particular sprite or sound effect from the
> sprite and
> sound effect lists for each item under this settings screen. then the
> main
> part of the game can simply use 'Game Over Sound Effect' at the
> appropriate
> time and
>
> the problem is that i cant save any of these settings values in any
> other
> object, because if i do it doesnt refer to the settings object, it will
> refer
> to whatever sprite/sound object the user selected, and then if he
> changes it,
> it wont have an effect... i want to be able to have a reference to
> these
> object reference variables, if possible...

You lost me at the part about 'then if he changes it'.

He selected the effect in the first place, and you are using that, so you
have
a means to use what the user selects. If he selects another effect he
has to
be on the settings screen as before, does ne not? Where can he make a
change
in what he selects other than on the settings screen (which you are
already
using)?

If it were me, I'd create a settings class and let the user alter its
property
values. Any code that needs to use one of the values gets it from the
settings class. If the user changes a value, it goes into effect on next
use
(because the code calls the same property he just changed....)

I just don't see a need for such indirection for user options. As long
as
you use the same property the users sets, how are you going to get out
of sync?

LFS

Nov 21 '05 #10

"Dave Cousineau ( Sahuagin )" <Da*******************@discussions.microsoft.com > wrote
all physical game objects will have a 'shadow sprite' object reference.
instead of the user (the user of the game design software not the game
itself) going to each new game object he creates and selecting a sprite for
the shadow there, he just goes into a settings form, and theres a setting for
'shadow sprite'. all game objects would now have a 'shadow sprite' member
that is a reference to a reference, which refers to the reference he selected
under the settings form.

is this taboo or something? its a simple question that seems like it could
easily be answered by just saying 'no there isnt'.


I believe it was aready mentioned that VB has no pointers....

But it appears you are complicating the situation. If you have a settings class,
and want to provide a default property for all objects, then (depending on who
you want to give priority to) have your objects check the settings class before
making use of any value, such as:

Public Class GameObject

Private mShadowSprite As Object

Public Property ShadowSprite() As Object
Get
If mShadowSprite Is Nothing Then
Return Settings.ShadowSprite
Else
Return mShadowSprite
End If
End Get

Set(ByVal value As Object)
mShadowSprite = value
End Set

End Property

End Class
Now, anytime GameObject.ShadowSprite is used, a check is made
to see if it has its own sprite, or if not, it uses the one set by the user.

In that instance, each object's sprite would override the default value.
You could make it the other way, where the default value overrides the
local value, or, some combination (where a checkbox indicates who gets
priority, etc.)

In any case, a reference to a reference is not needed, and, don't you
agree, just looking at the explaination of it, sounds overly complicated?

LFS
Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.