why the New in objDX8 as new DirectX8?

Started by
2 comments, last by Tevong 22 years, 2 months ago
I looked up New in my VB book but it doesn''t help much. Why do I have to put New to declare some objects like D3DX8 and not others?
Signed: ___T____
Advertisement
Come on it''s a simple question that''ll take two minutes of your life
Signed: ___T____
Without going into the sticky details, well suffice to say this. Classes need to have New in their declaration.(Not ALWAYS true, but for beginning VB its ok) Types and Vars dont, jsut classes.

An explanation why can be given if you want.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Democracy is where you say what you want and do what you''re told.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
The NEW keyword in Visual Basic is how you create a new instance of a class. A class is distinctly different than a Variable in VB.

If CMyClass were a class object you created, consider the following:

Dim mcDemo as CMyClass
Dim intTemp as Integer

A Variable is just an easy way to represent a place in memory, right? We, as programmers, reference by variable because it makes our life so much easier. The question of what is stored in that memory location is not one that VB programmers have to consider very often. In the case of an integer or string or whatever, the variable is a representation of the memory address where the data is stored. In the case of a class object, the variable is a representation of the memory address where ANOTHER memory address is stored. That second memory address is the address where the data is stored. You know the difference between ByRef and ByVal? If you took the ByVal of intTemp, you would get 7 or 9 or 232 or whatever was stored in the intTemp variable. If you took the ByVal of mcDemo, you would get a long address that would be meaningless to you.

When you use the NEW keyword, you actually dimension the memory for the instance of the class, so consider the following:

Dim mcDemo as New CMyClass

now, mcDemo contains a memory address that is the location of all of that CMyClass data. The NEW keyword is very important when working with any class object. You may notice alot of times if you Dim a variable for a collection, you cannot just use that varialbe like a collection object, you have to do something like:

Set dd7surf = DX7.CreateSurface(blahblahblah)

The Set keyword in that statement is important because it tells VB that you''re setting a class variable, not a regular variable. There is no NEW keyword, but there is a function (CreateSurface) that does the work the NEW keyword would normally do.

That was a little brief, any questions?

-Ben

--Ben Finkel

This topic is closed to new replies.

Advertisement