• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Wyzard;25118108]That's a good way to end up with multiple divergent versions of that code, with different sets of bugs and enhancements in each program that uses it. Better to factor it out into a separate library.[/QUOTE] DRY, etc., I know the arguments. I might try to dig through all my projects and stick the reusable code into a git repository or something at some point, but it's not a huge issue ATM because they're relatively bug-free and I don't have to touch them much (really, how could you possibly screw up a linked list?). Very little of it is generic enough for me to put into a proper library without modification.
[QUOTE=TerabyteS;25114233]I have followed a SDL tutorial, I was at the second one, at this page [url]http://lazyfoo.net/SDL_tutorials/lesson02/index.php[/url] I wrote all the code, compiled it and it gave no errors. Ran it and it terminated with condition 1, and nothing appeared on screen. Then I tried downloading the tutorial's source but that one didn't work either. What is it that's not working? There are 3 "return 1;" in this one, one is when setting up the screen, one when flipping it, one when loading the image. My guess would be the loading one, but I have no idea why its wrong [/QUOTE] The tutorial is a bit half-assed with error handling. Here's a better way: [cpp] //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { // stderr is routed to the same target as stdout by default (the console screen) fprintf(stderr, "error initializing SDL: %s\n", SDL_GetError()); return 1; } ... //If there was an error in setting up the screen if( screen == NULL ) { fprintf(stderr, "error creating SDL window: %s\n", SDL_GetError()); return 2; } ... //Update the screen if( SDL_Flip( screen ) == -1 ) { fprintf(stderr, "error flipping screen buffer: %s\n", SDL_GetError()); return 3; } ... return 0; // zero means success [/cpp] You can also create an enum for the different errors which lets you easily check them when invoked from other C programs.
This isn't really for anything specific, I was just thinking about it today Let's say I had a really massive array... for example, 3000 elements. What would be the most efficient way to randomise the order of that array? The algorithm must not add or remove any values to the array, it must only change the order. The most efficient I can come up with is something like this: [code] const int arrayLength = 3000; int *myArray = new int[arrayLength]; for(int i = 0; i < arrayLength; i++) { int randIndex = random(0, arrayLength); int temp = myArray[i]; myArray[i] = myArray[randIndex]; myArray[randIndex] = temp; }[/code] I'm interested to see what other people come up with
-snip-
[QUOTE=Chris220;25131935]Let's say I had a really massive array... for example, 3000 elements. What would be the most efficient way to randomise the order of that array?[/QUOTE] [url=http://www.cplusplus.com/reference/algorithm/random_shuffle/]std::random_shuffle[/url].
How do I change a pointer to point at a member of a class it is already pointing at? So lets say rect * rectpoint; rectpoing = rectpoint->x; How can I do that?
[QUOTE=WTF Nuke;25142264]How do I change a pointer to point at a member of a class it is already pointing at? So lets say rect * rectpoint; rectpoing = rectpoint->x; How can I do that?[/QUOTE] The way you just typed it...
No, it looks like he's trying to use a rect* to point to an int or something. rectpoint->x wouldn't be another rect.
Now I feel dumb because it works :saddowns:. This tinyxml parsing sucks. I keep getting errors like this [code]Unhandled exception at 0x010f1f44 in SFML Game.exe: 0xC0000005: Access violation reading location 0x0000003c.[/code] And it crashes on the tinyxml parser itself (these lines)[code]void TiXmlElement::ClearThis() { Clear(); while( attributeSet.First() ) { TiXmlAttribute* node = attributeSet.First(); attributeSet.Remove( node ); delete node; } }[/code]
Okay, this is getting a bit on my tits. I'm doing some assignments in Java and here's my problem: [cpp]package h03_opdracht1; import java.awt.*; import javax.swing.*; public class Lijnenpaneel extends JPanel { private int yPos; { public void paintComponent( Graphics g ) { super.paintComponent ( g ); g.setColor(Color.RED); int yPos = 0; while (yPos <=99) { g.drawLine(0, yPos, 49, yPos); yPos = yPos + 3; } } } [/cpp] In this state, line 9 gives me an error, telling me to add another } to complete the block. However, when I add one, my paintcomponent on line 10 decides to screw shit up: It gives me a syntax error on "(", ; expected. It also gives me a syntax error on ")", ; expected. void is an invalid type for the variable paintcomponent. What the hell is going on here? Especially the first 2 errors boggle the mind. Bear in mind, I'm very new to this.
[QUOTE=Sir Whoopsalot;25147240] [cpp]package h03_opdracht1; import java.awt.*; import javax.swing.*; public class Lijnenpaneel extends JPanel { private int yPos; { public void paintComponent( Graphics g ) { super.paintComponent ( g ); g.setColor(Color.RED); yPos = 0; while (yPos <=99) { g.drawLine(0, yPos, 49, yPos); yPos = yPos + 3; } } } [/cpp] [/QUOTE] If you haven't figured it out already you have a few extra brackets: [cpp]package h03_opdracht1; import java.awt.*; import javax.swing.*; public class Lijnenpaneel extends JPanel { private int yPos; public void paintComponent( Graphics g ) { super.paintComponent ( g ); g.setColor(Color.RED); yPos = 0; while (yPos <=99) { g.drawLine(0, yPos, 49, yPos); yPos += 3; } } } [/cpp] That should work; I suggest an IDE like Netbeans/Eclipse/CodeBlocks or just Notepad++ to help with bracket matching.
[QUOTE=WhatCannon?;25148378]If you haven't figured it out already you have a few extra brackets: [cpp]package h03_opdracht1; import java.awt.*; import javax.swing.*; public class Lijnenpaneel extends JPanel { private int yPos; public void paintComponent( Graphics g ) { super.paintComponent ( g ); g.setColor(Color.RED); yPos = 0; while (yPos <=99) { g.drawLine(0, yPos, 49, yPos); yPos += 3; } } } [/cpp] That should work, using an IDE like Netbeans/Eclipse/CodeBlocks will help with things like that in the future.[/QUOTE] I am using Eclipse, which probably only makes it more embarassing.
[QUOTE=WTF Nuke;25143072]Now I feel dumb because it works :saddowns:. This tinyxml parsing sucks. I keep getting errors like this [code]Unhandled exception at 0x010f1f44 in SFML Game.exe: 0xC0000005: Access violation reading location 0x0000003c.[/code] And it crashes on the tinyxml parser itself (these lines)[code]void TiXmlElement::ClearThis() { Clear(); while( attributeSet.First() ) { TiXmlAttribute* node = attributeSet.First(); attributeSet.Remove( node ); delete node; } }[/code][/QUOTE] 0x3c is pretty near 0x0, so it could be a NULL pointer. In your code (offset due to accessing a member).
[QUOTE=Wyzard;25139262][url=http://www.cplusplus.com/reference/algorithm/random_shuffle/]std::random_shuffle[/url].[/QUOTE] Very nice, but I was kinda interested in "homemade" algorithms, if you will
I've got this constructor that takes 4 textures (my class). I want only one of them to be obligatory and the other 3 optional. The way I see it I have 3 options. 1. Make them nullable but that gives me this error Error 1 The type 'Texture' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>' 2. Make them have default values. For that I made a static Texture in the Texture class called null that is filled with invalid data (data that no valid texture could have) but they gives me the "Parameter must be a compile-time constant" thing. 3. Make a different constructor for every combination of specified textures. You can see the flaw right there and I'm sure there's a better solution. Please help.
[QUOTE=Darwin226;25158072]I've got this constructor that takes 4 textures (my class). I want only one of them to be obligatory and the other 3 optional. The way I see it I have 3 options. 1. Make them nullable but that gives me this error Error 1 The type 'Texture' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>' 2. Make them have default values. For that I made a static Texture in the Texture class called null that is filled with invalid data (data that no valid texture could have) but they gives me the "Parameter must be a compile-time constant" thing. 3. Make a different constructor for every combination of specified textures. You can see the flaw right there and I'm sure there's a better solution. Please help.[/QUOTE] You could try using the [url=http://msdn.microsoft.com/en-us/library/w5zay9db.aspx]params[/url] keyword
Wouldn't work as I need to know in the constructor which textures were given. Params only allows me to see how many of them there are, not which ones specifically.
You could create your own texture-class, which is nullable and stores the texture-type along with the texture.
Well... the texture IS my own class. How do I make it nullable?
It already is if it's a class. [editline]02:35PM[/editline] Just have constructor overloads: [cpp] class Whatever { public Whatever(Texture a) : this(a, null, null, null) { } public Whatever(Texture a, Texture b) : this(a, b, null, null) { } public Whatever(Texture a, Texture b, Texture c) : this(a, b, c, null) { } public Whatever(Texture a, Texture b, Texture c, Texture d) { // stuff } } [/cpp] [editline]02:36PM[/editline] Classes are reference types which means they are inherently nullable. Structs, however, are value types which can only be made nullable if they're wrapped with a reference type - in most cases, Nullable<T>
Is there an sql statement which will alter a table if it needs to be? Or is there a program for creating a difference sql file?
How could I get longitude and latitude (I dont need any other info) of an IP address?
Can you call methods as part of variable assignments in most object oriented C languages? I'm using Objective-C, here's what I'd imagine it'd look like, say object is a pointer to the object: int aVar = [object methodThatReturnsSomething];
[QUOTE=ProWaffle;25173432]Can you call methods as part of variable assignments in most object oriented C languages? I'm using Objective-C, here's what I'd imagine it'd look like, say object is a pointer to the object: int aVar = [object methodThatReturnsSomething];[/QUOTE] I don't know Objective-C and your question is a bit strange, so I might be misinterpreting it. Anyway, yeah, that's absolutely possible (and common). Let's assume "object" is a pointer to a class instance with a method 'foo' taking no arguments, returning an integer. C++ [cpp] int var = object->foo(); [/cpp] C#, Java, D, C++ (object being a reference, not a pointer) [cpp] int var = object.foo(); [/cpp] To elaborate, the right side of a C-style assignment can be any expression yielding a value of a compatible type. These expression results are called "rvalues" (because in C-style assignments, they appear on the right). Examples of rvalues include literals, other variables, the result of arithmetic operations, the return value of a function or method call; almost anything is a valid rvalue (with some language-specific reservations). The opposite of an rvalue is an lvalue, in short, stuff that is assignable. This includes variables, a dereferenced pointer; stuff you can "write" to. All lvalues are valid rvalues, but not the other way around. C-style syntax is arguably quite intuitive so this stuff is not something most people need to know the specifics of, but it's useful in understanding the syntax in depth and understanding compile error messages.
[QUOTE=ProWaffle;25173432]Can you call methods as part of variable assignments in most object oriented C languages? I'm using Objective-C, here's what I'd imagine it'd look like, say object is a pointer to the object: int aVar = [object methodThatReturnsSomething];[/QUOTE] Well you can't call methods in Objective-C without them being pointers :P But what you have above is absolutely fine. Though *technically*, it should read [cpp] NSInteger aVar = [object methodThatReturnsSomething]; [/cpp] And that is only because you will actually get compiler warnings about int not being the same size when compiling for multiple platforms.
Help! I was wondering if the XNA's content manager was making sure that you don't load the same texture multiple time even if you call the .Load method multiple times (for the same texture).
Hmm... Despite all the dumb ratings, this Thread is quite successful...
[QUOTE=Loli;25182398]Hmm... Despite all the dumb ratings, this Thread is quite successful...[/QUOTE] More like [B]despite the fact it was made by Chad[/B].
esa gonna hate
[QUOTE=sim642;25173394]How could I get longitude and latitude (I dont need any other info) of an IP address?[/QUOTE] The term to search for is "geolocation". Be aware that it's not an exact science, though. There are free services that can give you a general area like a city based on looking up the ISP that the address is assigned to, but I don't know that they can be more accurate than that. I've read that Akamai has a more sophisticated service that incorporates time-delay measurements from various known locations, but that probably costs money, and I doubt it's completely precise.
Sorry, you need to Log In to post a reply to this thread.