Archived

This topic is now archived and is closed to further replies.

a quick Q on c, c++ and directx(<--kinda)

This topic is 6396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I learned c++ originally, then bought this great book, "tricks of the windows game programming gurus", in order to try my hand at game programming. The book though, uses c. Now, of course I know that c + c++ are compatible, but how much so? can i use snippets of both languages in the same *.cpp file? The problem is that i dont know how much of the stuff that the book has taught me is straight c, and how much is c/c++ (like using structs instead of classes, whats that about?) will this be a problem? for example, heres a call from the books directx section: lpdd->SetVideoMode(640, 480, 256); now it seems to me that the -> should be a ::. or is the -> a COM thing? or this piece of code near the beginning of WinMain() WNDCLASSEX wndclassex; there''s no assignment operator! is this ok? is this a c thing? IF ANYONE HAS HAD A SIMILAR PROBLEM ****I WOULD APPRECIATE ANY HELP/QUICK LESSONS YOU COULD GIVE ME**** (on changing c to c++ or using both or whatever)

Share on other sites
Get "Teach Yourself DirectX 7 in 24 hours"

Use the book you have as a guide for hints on how to do things but not for the source itself.

Ben

Share on other sites
The book, as you have already stated, uses C as the language to show you how to program DirectX as 99% of windows programming is in C.

the lpdd->SetVideoMode(...); line is correct as the lpdd is a ''sort of'' class that is mapped onto a COM object (A COM object can be thought of as a class in SOME respects but not all).

You also noted that you know C++, do you know what pointers are? and how you would reference a class function from a class pointer? as that is what the -> is for.

WNDCLASSEX is a struct (a struct is a class without functions in pure C, but in C++ they have functions - but lets just keep this simple!) and the line that you mentioned is defining a new variable.

Are you sure you know C++ at all??? The reason I''m asking is that you are asking questions on basic C & C++ coding. Since C++ is C with Objects (A quote from a book I read once!) C and C++ are interchangable to a point.

I would sugest getting a gook book on Windows programming before you look at DirectX (even if it helps explain what the hell is going on with the basic window setup code) Windows 98 Programming from the Ground Up is a good one (includes information on all of the custom controls, etc) and then get a book on C/C++, say C++ the complete reference (it explains the difference between C and C++ a bit more than me in this post). Then start to look at DirectX.

This is just my opion and therefor it is bias towaords what I know.

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

Share on other sites
This is going to sound like a bitch, but it is not meant to be. If you do not know what the things your describing are - you did not learn C++ as well as you think you did.

The -> thingy functions the same way the ''dot'' does when referencing a structure member, except it''s for pointers.

The WINDCLASSEX thing is a typedef. There does not need to be a = sign or anything because it is not an assignment, it is a declaration (just like "int INT;") That is legal because C/C++ is case sensative.

The following is an example of both things.

typedef struct FOO{   int num;   char type;   };FOO* tmpFoo;tmpFoo->num = 0;

Also - just make sure you keep your problems seperated. These are language problems. The book mentioned would not help with these probs, only API probs.

Good luck,
Landsknecht

Share on other sites
I had no problem using any of the code in c++.

Share on other sites
> know that c + c++ are compatible, but how much so? can i use
> snippets of both languages in the same *.cpp file?

From the creator of C++ (Bjarne Stroustrup):
C++ is a general purpose programming language with a bias towards systems programming that
is a better C
supports data abstraction
supports object-oriented programming
supports generic programming.

''compatible'' is a poor choice of words, but most ANSI c code will compile in a C++ compiler (most, because for example ''class'' would be a valid variable name in C, not so in C++ where it is a reserved keyword).
A C compiler won''t understand C++ though.

struct and class are equivalent in C++, with the exception that a struct''s members default to public whereas a class'' default to private.

> now it seems to me that the -> should be a ::. or is the -> a > COM thing?

It''s not a COM thing. And the scope operator "::" can''t be used in this context. The "->" operator is a shortcut for "(*Variable)." which means ''pointer dereferencing and member access''. The brackets are necessary because "." comes before "*" in the operator precedence table. So "->" was introduced as a convenient shortcut.

> WNDCLASSEX wndclassex;
> there''s no assignment operator! is this ok? is this a c thing?

not a c thing but a standard variable declaration (wndclassex is of type WNDCLASSEX). Don''t you just hate those names?! I find them close to unreadable...

> IF ANYONE HAS HAD A SIMILAR PROBLEM ****I WOULD APPRECIATE ANY > HELP/QUICK LESSONS YOU COULD GIVE ME****

Sorry to tell you, but you don''t need some ''quick lessons'' but rather some serious study. Get yourself a good book. Can''t remember the name, but there is one available on the net for free.

BuschnicK

Life would be much easier if I had the source code.

Share on other sites
quote:
Original post by BuschnicK

Sorry to tell you, but you don''t need some ''quick lessons'' but rather some serious study. Get yourself a good book. Can''t remember the name, but there is one available on the net for free.

"Teach yourself C++ in 21 days by erm i think Jesse Liberty (might be completely wrong there so dont yell at me )
Anyway its at www.informit.com

Just my thoughts take them as you will.

"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face

1. 1
2. 2
JoeJ
20
3. 3
frob
18
4. 4
5. 5

• 10
• 10
• 12
• 13
• 9
• Forum Statistics

• Total Topics
632200
• Total Posts
3004739

×