• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

C++ Help?

Status
Not open for further replies.

C-Jo

Member
rhfb said:
C# is very nice. Not great for everything obviously, but if you aren't needing the raw horsepower of something like C/C++ then C# isn't a bad choice.
This is my first foray into anything programming-related so it's still pretty slow going. Well other than Kismet, but that doesn't really count.
 

AcciDante

Member
Do you guys think I could jump into obj-c with my limited C++ knowledge, and be able to figure it out? I'd get a book of course.
 

Chris R

Member
AcciDante said:
Do you guys think I could jump into obj-c with my limited C++ knowledge, and be able to figure it out? I'd get a book of course.
Yes, shouldn't be any problem. Might not even need a book. If you do get one though I'd get a Hillegass book (iPhone if that is what you are going to focus on, OSX/Cocoa if you are just doing general Obj-C stuff).
 

subrock

Member
I'm jumping into python as my first language this semester at college. its not warping my mind yet, but I'm sure it will. we move on to the harder language next semester which is when I'm sure I'l be digging up this thread :D
 
Ok, I have a problem with c++ but since there is this recent thread I don´t want to create another one. I have limited experience in C# with XNA and have to create a game menu in a short timespan. I know I should do some tutorials, but I don´t have the time for that. I´m using Haaf´s Game Engine to create a game in a team. But I can´t get the tutorials to work.
I hope someone has experience with this engine, this is my problem:

I already did the steps mentioned here on this site in setting up a HGE Project: http://hge.relishgames.com/doc/index.html and am doing in tutorials, tutorial 6 "Creating a Menu".

I don´t know how to include that source code in my project. I replace the text of the cpp file it creates when creating a Win32 Project with the source code from the tutorial, but can´t get it to debug.

I first get this error fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

So after I add this I get this error: fatal error C1083: Cannot open include file: 'menuitem.h': No such file or directory
And two warnings that look like that.

I can´t debug then because it says it can´t find an exe file of my project, so how do I make this?

EDIT: According to somebody else I had to put the hge.dll in my debug folder. But if I now include stdafx it will report over hundred error and still give the same message without.
 

AcciDante

Member
Oh god, pointers.

Working on my assignment, and I'm unsure how to make a function that takes a newly allocated array of integers, if that makes sense.

Code:
ptrStud = new int[students];

'students' was already inputted earlier in the program, but how do I now use that new array in a function? (The function will have data in it when I need it.)

Code:
//is this prototype correct?
double getAverage(int *, int);

//is this call correct?
getAverage(ptrStud, students);
 

jvalioli

Member
Looking good.

On how to use.

int[] is the same as int* const ( constant pointer to a mutable int)

Not sure about C++ pointer arithmetic, but if it is just like C you can iterate doing something like...

int[] arr = new int[size];

int* p = arr;

while(size--){
printInt(*p)
p++;
}

Just make sure whatever you're doing the ++ on is declared as a int*. I'm not sure what you used because you left off the declaration, but I'm guessing its an int* anyway.
 

Zoe

Member
jvalioli said:
while(size--){
printInt(*p)
p++;
}

As much as I hate doing postfix operations, it does work in this case. I wouldn't use it though unless you understand exactly what's happening here.
 

AcciDante

Member
Alright, well I got it all coded out, but am getting an error for a variable not being initialized when I used it. I made a smaller example of what I did so I don't have to post the whole assignment.

Code:
#include <iostream>
using namespace std;

int main()
{
    int total;
    int *ptr;

    ptr = new int[5];

    for (int i = 0; i < 5; i++)
    {
        cout << "enter #" << i + 1 << ": ";
        cin >> *(ptr + i);
    }

    for (int i = 0; i < 5; i++)
    {
        total += *(ptr + i);
    }

    cout << "total is " << total << endl << endl;

    delete [] ptr;
    ptr = 0;

    return 0;
}

It says the variable 'total' is being used without being initialized. How'd I mess up?
 

kadotsu

Banned
AcciDante said:
Alright, well I got it all coded out, but am getting an error for a variable not being initialized when I used it. I made a smaller example of what I did so I don't have to post the whole assignment.

code

It says the variable 'total' is being used without being initialized. How'd I mess up?

total = 0;
 

Zoe

Member
AcciDante said:
It says the variable 'total' is being used without being initialized. How'd I mess up?

Initialize it to 0. Right now it's trying to add null to your first element in the array.

BTW, it'd be more efficient if you did your operations on ptr alone instead of computing (ptr + i) each time.
 
Relix said:
Can anyone recommend me a good C++ teach yourself book? =)
Did you hear about the MSDN soup to nuts series? I recommend the C# Soup to Nuts. C++ is kinda old and not many businesses use it. C#, VB and J# is where the money is. Follow the series list from here: Link
Watch the webcasts here: Link 2 (or better yet, you can just google "C# Soup to nuts MSDN" and add the webcast you wanna watch. Each webcast is around an hour, and its all free.

Another important thing to learn is the .NET framework. The soup to nuts series explains it to you pretty well. Not in great detail, but important, pertaining points.
 

Relix

he's Virgin Tight™
I am actually more interested in C# as C++ has always looked so obtuse and confusing to me. I just want to learn it as a hobby, nothing much, maybe some bored day have enough knowledge to make a 2D game or something :lol

I have programming experience with Basic, specifically using Visual Studio .NET so I have a good idea of the .NET framework.
 
That's cool! Yeah I would suggest watching the webcasts and trying out stuff by downloading Visual express. 22 webcasts = 22 hours and by the time you're done with them, you should be in the medium to advanced territory. And then you should start on the ASP.NET series :p

I do think the webcast #21 offers a good intro into XNA game development.
 
I would say that if C++ looks obtuse for you, you're going to have trouble in a lot of other languages. A good knowledge of c/c++ will get you a long ways.
 

Seda

Member
Relix said:
I am actually more interested in C# as C++ has always looked so obtuse and confusing to me. I just want to learn it as a hobby, nothing much, maybe some bored day have enough knowledge to make a 2D game or something :lol

I have programming experience with Basic, specifically using Visual Studio .NET so I have a good idea of the .NET framework.


I just started a class where we use C# in both a ASP.NET framework and for Window's forms.

It's awesome, it just clicks with me.
 

deadbeef

Member
Seda said:
I just started a class where we use C# in both a ASP.NET framework and for Window's forms.

It's awesome, it just clicks with me.

I really love C#. I use it whenever I get the chance.

However, if you ever have to marshal any nasty data structures across managed code boundaries, it's a real pain in the ass. You just want to scream "let me at the bytes! I know what I'm doing!!!"
 

Relix

he's Virgin Tight™
Gonna try C# then. Will look at those webcasts RustyNails.

I would like additional to that a book suggestion then. I like to slowly read things, then do tutorials, etc.
 
RustyNails said:
Did you hear about the MSDN soup to nuts series? I recommend the C# Soup to Nuts. C++ is kinda old and not many businesses use it. C#, VB and J# is where the money is.
A rather dubious assertion.

.NET is okay, but GUI programming is GUI programming, more or less. Tens of languages will do. Start with C# or Java (if you want to write Windows GUI programs, C#), or maybe better yet Python if you have no programming experience. Move around from there.

My general advice in regards to C++ is: disregard templates. Pretend they don't exist. Not forever, but until you have a grasp on the rest of the language... just don't use them. You almost certainly won't need the functionality they provide, and the nearly incomprehensible compiler explosions they lead to is not worth it for anyone but an experienced programmer.
 
deadbeef said:
I really love C#. I use it whenever I get the chance.

However, if you ever have to marshal any nasty data structures across managed code boundaries, it's a real pain in the ass. You just want to scream "let me at the bytes! I know what I'm doing!!!"
You can basically turn c# into c++ and directly manipulate pointers using the "unsafe" operator, like this:

Code:
unsafe
{
// do direct memory operations here
}
 
CrayzeeCarl said:
You can basically turn c# into c++ and directly manipulate pointers using the "unsafe" operator, like this:

Code:
unsafe
{
// do direct memory operations here
}

Make sure not to use this for everything! I've heard people joke about putting everything C# in unsafe{} and just use pointers and such things which are abstracted from you normally, but that is extremely stupid, and I hope noone out there actually does that (if you want that, use C++).

I usually give me same advice in these threads: Start with C# to see if you like programming, move to C to get the basics of the language and prove you're serious, and then add on all of the extra complexity with C++. Why C before C++? It's "simpler", and also there are tons of great books on it, and the "bible" for it is nice and skinny. Once you master that, it's a cakewalk moving to C++.
 
Iced_Eagle said:
Make sure not to use this for everything! I've heard people joke about putting everything C# in unsafe{} and just use pointers and such things which are abstracted from you normally, but that is extremely stupid, and I hope noone out there actually does that (if you want that, use C++).

I usually give me same advice in these threads: Start with C# to see if you like programming, move to C to get the basics of the language and prove you're serious, and then add on all of the extra complexity with C++. Why C before C++? It's "simpler", and also there are tons of great books on it, and the "bible" for it is nice and skinny. Once you master that, it's a cakewalk moving to C++.
Absolutely. I only used this for when I had to interface with unmanaged dll's.
 

Zoe

Member
I think you could get away with skipping C and going straight to C++. They didn't even offer any C classes in my CS program (EE had it though).
 

teh_pwn

"Saturated fat causes heart disease as much as Brawndo is what plants crave."
Is there a breakdown of language popularity in the job market? I find the comment that that C/C++ isn't used a lot very surprising. I thought it was widely used. I program in it anyway, and MS has 10,000 builds of MSVC C++ run-time it seems.
 

teh_pwn

"Saturated fat causes heart disease as much as Brawndo is what plants crave."
Father_Mike said:
I would say that if C++ looks obtuse for you, you're going to have trouble in a lot of other languages. A good knowledge of c/c++ will get you a long ways.

Yeah, I agree. Learning the basics of data structures, memory allocation, and OOP seems easier in C++ because it's not as high level. You have to learn how to do it. Seems like all of these kids and their damn music slapping shit together with high level bloated languages. *shakes fist at cloud*
 

Zoe

Member
teh_pwn said:
Is there a breakdown of language popularity in the job market? I find the comment that that C/C++ isn't used a lot very surprising. I thought it was widely used. I program in it anyway, and MS has 10,000 builds of MSVC C++ run-time it seems.

I believe all the systems stuff at my company has moved on to C#--partly because of ASP.Net. The games division might still be using C++ though.
 

AcciDante

Member
Relix said:
Can anyone recommend me a good C++ teach yourself book? =)

My class uses THIS book, and I've been able to go through it by myself pretty easily.

Thanks for all the help guys, I got it properly functioning :D
 
AcciDante said:
My class uses THIS book, and I've been able to go through it by myself pretty easily.

Thanks for all the help guys, I got it properly functioning :D


I also own this book from my first year class. It's good for ateach your self book.
 

Relix

he's Virgin Tight™
Oh damn Acci I was looking for something like that. I also use Gaddis's book for VB and its excellent. Sorry for the slight derail but I really wanted to learn another language aside from Basic and really put time into it. Thank for the responses everyone :D
 

Naka

Member
I'm really glad I learned C++ in college as my foundation for programming. When I graduated I got a job doing C#/ASP.NET. When I first started learning C# it seemed so much easier after having a solid grasp on C++. I've been doing it for 5 years professionally now and I think I'd have a hard time going back haha.
 

XiaNaphryz

LATIN, MATRIPEDICABUS, DO YOU SPEAK IT
teh_pwn said:
Is there a breakdown of language popularity in the job market? I find the comment that that C/C++ isn't used a lot very surprising. I thought it was widely used. I program in it anyway, and MS has 10,000 builds of MSVC C++ run-time it seems.
Depends on the needs of the application. If you're just making basic desktop apps or tools, something like C# probably will be fine. If you need heavy duty performance, you're likely going to go C++. Our R&D group at ILM is mostly C++ for our in-house needs for modeling/animation/rendering/simulation/previewing/previz, use Python for the more lightweight script stuff, and Qt/PyQt for GUI needs. Our guys do some pretty advanced hardcore stuff though, several of the engineers have masters or PhDs and most of the technical detailed stuff goes over my head. :lol

Other vfx houses or animation studios are the same.
 

ULTROS!

People seem to like me because I am polite and I am rarely late. I like to eat ice cream and I really enjoy a nice pair of slacks.
XiaNaphryz said:
Pffft...any hardcore compiler guys around here? Let's throw some assembly into the mix. ;P

I constructed a parser/compiler in C (not C++). Does that count?
 
I guess I can ask gaf for help on this one. So I I'm taking a class that's using C and I've used it before. Well in discussion the TA wrote this out:


while(*ptr++ != 0)
sum = sum + *(ptr++);​


Doesn't this mean ptr is incremented twice, once in the ()'s of the while and in the body of the while? Or does incrementing ()'s of the while not affect it? It seems kind of dumb, but they didn't teach any C basics, it was more of hey you guys know java so do these problems in C.

Thanks!
 

usea

Member
cool_trainer said:
I guess I can ask gaf for help on this one. So I I'm taking a class that's using C and I've used it before. Well in discussion the TA wrote this out:


while(*ptr++ != 0)
sum = sum + *(ptr++);​


Doesn't this mean ptr is incremented twice, once in the ()'s of the while and in the body of the while? Or does incrementing ()'s of the while not affect it? It seems kind of dumb, but they didn't teach any C basics, it was more of hey you guys know java so do these problems in C.

Thanks!
It seems that way at first, but the * operator has priority over ++. So "*ptr++" in the while loop actually increments whatever is at the location being pointed to. Whereas the "*(ptr++)" inside the loop increments the pointer itself (and adds the thing pointed to to the sum).

Somebody correct me if I'm wrong.
 

V_Arnold

Member
I started using XNA about half a year ago, but did not really dwell into it until last week, when I decided it is time to write a fully functional Tetris for educational purpose (obviously :D). Took me 5 nights, each night around 1-2 hour of programming, and in the daytime, a little thinking about the logic behind the tetris block system. It is awesome how many ways there are to create that, and the best/worst part is that every implementation has its own problems.

My next goal is to create a basic Tower Defense game. Hopefully PNG assets are usable in AS also.

And while I am here, a quick question: is there any way to check what variable goes over the edge when the code tries to apply into the n+1th row in an [n][n]-sized two dimensional array? All I could figure out in Visual Studio was the line which breaks, but not the variable which tries to pass the boundrary.... any suggestions? I did find it later, but for future use, I would not really want to look in huge codes when there is an option to show the passed value...
 
usea said:
It seems that way at first, but the * operator has priority over ++. So "*ptr++" in the while loop actually increments whatever is at the location being pointed to. Whereas the "*(ptr++)" inside the loop increments the pointer itself (and adds the thing pointed to to the sum).

Somebody correct me if I'm wrong.

I see what you mean, thanks. Okay how about say you increment in the ()'s in a while loop like this:

while(i++ < 10)
{
stuff here​
}

Would i be incremented immediately after that i < 10 check before going on to the body of the while or is i incremented after performing the steps in the body of the loop?
 

Zeppu

Member
cool_trainer said:
I see what you mean, thanks. Okay how about say you increment in the ()'s in a while loop like this:

while(i++ < 10)
{
stuff here​
}

Would i be incremented immediately after that i < 10 check before going on to the body of the while or is i incremented after performing the steps in the body of the loop?

i++ means that i is incremented right after that particular statement is completed (which in that case is the comparison of i and 10)

So basically it's:
i < 10?
i = i + 1;

If you want to flip the above steps, i.e.
i = i + 1;
i < 10?
then simply change to

while (++i > 10) { ... }
 
josephdebono said:
i++ means that i is incremented right after that particular statement is completed (which in that case is the comparison of i and 10.

So basically it's:
i < 10?
i = i + 1;

If you want to flip the above steps, i.e.
i = i + 1;
i < 10?
then simply change to

while (++i > 10) { ... }

Thanks, I wasn't completely sure if the body of the while was considered part of the statement.
 

Zeppu

Member
No. In fact if you were to have the following statement:

while ((i++ < 10) && (i > 0))
{

}

Lets assume i = 0 at the start.
(i++ < 10) ---> i = 0 therefore i is smaller than 10.
i = 1 + i = 1.
(i > 0) ---> i is now 1 therefore i is greater than 0.
i = 1

If you were to change the expression to
while ((i++ < 10) && (i++ > 0))

then i would increment twice while evaluating that particular expression.

Remember that at the end of the day ++/-- are operators and therefore can only be manipulated whilst they are being accessed. The way a unary operator such as these works is basically as follows (pseudocode):

int function++() {
int x = this;
this = this + 1;
return x;
}

int ++function(){
this = this + 1;
return this;
}

(you can actually overload these functions in C++ :D)
 

ZealousD

Makes world leading predictions like "The sun will rise tomorrow"
Real men program in ML.

Oh dear god never program in ML.
 

Zoe

Member
josephdebono said:
int function++() {
int x = this;
this = this + 1;
return x;
}

int ++function(){
this = this + 1;
return this;
}

This part is very important. Notice that the post-fix returns the original value while the pre-fix returns the updated value. Keep that in mind whenever using these in a conditional statement.
 
Status
Not open for further replies.
Top Bottom