• What do you need help with? Version 1
    5,001 replies, posted
atoi expects a C-style string - that is, a pointer to the first char with a null character after the last. Grabbing individual characters from the string gives you just the character - no null character termination like in a C-style string. If the string starts with the number you want converted, just use atoi(S.c_str()). string.c_str() will return a C-style string which atoi can use.
I think TerabyteS wants each character to be parsed as a number individually? If so, then you could simply do this: [cpp]int digit; for(std::string::const_iterator iter = S.begin(); iter != S.end(); ++iter) { digit = *iter - '0'; if(digit < 0 || digit > 9) return OUT_OF_RANGE; //or whatever doSomethingWith(digit); }[/cpp]
[s]how can you have a multidimensional float array function in c++?[/s] Managed to do it without the need of returning a multidimensional array
-snip- :(
[QUOTE=jA_cOp;27385880]I suspect you mean something like runtime introspection, which you do get in dynamic languages and languages with featureful runtimes like .NET and JVM (but not with the default C++ runtime, if that's what you are using). Google "reflection" or "runtime introspection". [editline]13th January 2011[/editline] Use a XOR cipher with a one-time pad.[/QUOTE] Compile-time introspection, is it possible?
[QUOTE=mmavipc;27398668]Compile-time introspection, is it possible?[/QUOTE] Well that depends on the language you're using. Only language I know with compile time introspection is D.
[QUOTE=jA_cOp;27399359]Well that depends on the language you're using. Only language I know with compile time introspection is D.[/QUOTE] Damn. Holy shit Damn starts with D. I thought of a way to do it without introspection
Quick question here: If the condition in my for loop, is i<7, will it run through the loop once with i as 7? In other words, is i++ done before or after the check?
[QUOTE=no-named;27408113]Quick question here: If the condition in my for loop, is i<7, will it run through the loop once with i as 7? In other words, is i++ done before or after the check?[/QUOTE] Before the check
*fixed*
[QUOTE=no-named;27408113]Quick question here: If the condition in my for loop, is i<7, will it run through the loop once with i as 7? In other words, is i++ done before or after the check?[/QUOTE] No, the loop will not run. The check is done before every iteration and i++ occurs at the end of each iteration. If you want the code to always execute at least once, you can use a do while loop.
I need to pass a "const sf::Input& Input = App.GetInput();" to a function (or have a way to access it from the function anyway) so that from inside the function I can do: "Input.GetMouseX();" How is that done?
[QUOTE=TerabyteS;27411048]I need to pass a "const sf::Input& Input = App.GetInput();" to a function (or have a way to access it from the function anyway) so that from inside the function I can do: "Input.GetMouseX();" How is that done?[/QUOTE] What do you mean? It's done like passing any other argument: [cpp] somereturntype_t somefunc(const sf::Input&); ... const sf::Input input = App.GetInput(); somefunc(input); [/cpp]
[QUOTE=TerabyteS;27411048]I need to pass a "const sf::Input& Input = App.GetInput();" to a function (or have a way to access it from the function anyway) so that from inside the function I can do: "Input.GetMouseX();" How is that done?[/QUOTE] [cpp] void doInputStuff(const sf::Input& input) { /* use input.GetMouseX() */ } void handleInput(const sf::Window& window) { doInputStuff(window.GetInput()); } [/cpp]
Thank you very much. I'm impressed by how helpful and kind you guys are every time more :buddy: [editline]14th January 2011[/editline] (for future reference, I hadn't put the & near Input in the "int *getMousePos( int *destArray, const sf::Input& input )" line) [editline]14th January 2011[/editline] Uhm, I'm still having some problems. Appearently, a sf::RenderWindow can't be copied (I tried taking it into the function like you suggested for input). How can I call its functions from inside the function then?
[QUOTE=TerabyteS;27412130]Thank you very much. I'm impressed by how helpful and kind you guys are every time more :buddy: [editline]14th January 2011[/editline] (for future reference, I hadn't put the & near Input in the "int *getMousePos( int *destArray, const sf::Input& input )" line) [editline]14th January 2011[/editline] Uhm, I'm still having some problems. Appearently, a sf::RenderWindow can't be copied (I tried taking it into the function like you suggested for input). How can I call its functions from inside the function then?[/QUOTE] Passing it by reference or pointer doesn't copy it. Make sure you're passing it by reference/pointer and not trying to pass it by value (e.g. make sure you're using a & or *).
I did this [cpp]void render( sf::RenderWindow& App ) { App.Clear(sf::Color(250, 0, 0)); App.Display(); }[/cpp] And got this [code]C:\SFML-1.6\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private| C:\SFML-1.6\include\SFML\Window\Window.hpp|56|error: within this context| C:\SFML-1.6\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private| C:\SFML-1.6\include\SFML\Window\Input.hpp|45|error: within this context| C:\SFML-1.6\include\SFML\Window\Window.hpp|56|note: synthesized method 'sf::Input::Input(const sf::Input&)' first required here | C:\SFML-1.6\include\SFML\Graphics\RenderWindow.hpp|46|note: synthesized method 'sf::Window::Window(const sf::Window&)' first required here | D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp||In function 'int main()':| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|72|note: synthesized method 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' first required here | D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|72|error: initializing argument 1 of 'void render(sf::RenderWindow)'| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|27|warning: unused variable 'NewCells'| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|31|warning: unused variable 'r_surv'| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|32|warning: unused variable 'r_live'| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|36|warning: unused variable 'MPosL'| D:\CodeBlocks\Projects\GameOfLifeMulti\main.cpp|38|warning: unused variable 'Evolve'| ||=== Build finished: 5 errors, 5 warnings ===| [/code]
[code]initializing argument 1 of 'void render(sf::RenderWindow)'[/code] Then you compiler is screwing up (since the error should say sf::RenderWindow&), or you have a mistake in your forward declaration, if you're doing one.
[QUOTE=ZeekyHBomb;27412671][code]initializing argument 1 of 'void render(sf::RenderWindow)'[/code] Then you compiler is screwing up (since the error should say sf::RenderWindow&), or you have a mistake in your forward declaration, if you're doing one.[/QUOTE] Fuck, I had left the declaration at top unchanged. Please forgive my stupidity. [editline]14th January 2011[/editline] Um, are those forward declarations actually needed? Can't I just leave the function under main or will it give me an error because it can't find it?
This "Monodevelop" seems really useless, it can't handle resources. Crashes the program when i run it, does it work for anyone else? [url]http://braxnet.org/temp/unifrog.exe[/url] I really want to have it multiplatform, but it just doesn't want to work. How nice, if i start a new solution and just build&run it, it crashes! Is it supposed to do this?
[QUOTE=TerabyteS;27413476] Um, are those forward declarations actually needed?[/QUOTE] Yes, they are. C++ is full of legacy stuff like that.
[QUOTE=jA_cOp;27415239]Yes, they are. C++ is full of legacy stuff like that.[/QUOTE] Why are forward declarations "legacy stuff"? You can't even make functions without forward declarations in lua.
[QUOTE=yakahughes;27415715]Why are forward declarations "legacy stuff"? You can't even make functions without forward declarations in lua.[/QUOTE] ... what? Lua doesn't have function declarations, only local variable declarations. Also, remember that Lua scripts are executed top-down. The script is the entry point. That's nothing like a language like C++ where all functions are pre-compiled. You can't read a global variable in Lua before it's set and expect something non-nil. Modern compiled languages use module systems with symbol table setups allowing for (implicit) forward referencing and circular dependencies (Java, C#, D, etc). C++ is stuck with the virtually module-less system of using header files borrowed from C.
[QUOTE=jA_cOp;27416099]... what? Lua doesn't have function declarations, only local variable declarations. Also, remember that Lua scripts are executed top-down. The script is the entry point. That's nothing like a language like C++ where all functions are pre-compiled. You can't read a global variable in Lua before it's set and expect something non-nil.[/QUOTE] Yes I know, I'm just drawing some parallels to more modern languages, even if they don't work for a different reason. And I wasn't referring to globals, I meant when you do local function [name] below where the function is used without doing local [name] above it. [Unrelated: I think the reason it does this is because functions (have/are?) lexical closures which save their environment and the local variable declaration isn't in the environment yet, so it doesn't get it]) The way C++ does it (requiring only declarations above their use instead of the actual definition which can be anywhere) allows you to do stuff which would otherwise be more difficult which I don't care to go into now.
[QUOTE=yakahughes;27416806]Yes I know, I'm just drawing some parallels to more modern languages, even if they don't work for a different reason. And I wasn't referring to globals, I meant when you do local function [name] below where the function is used without doing local [name] above it. [Unrelated: I think the reason it does this is because functions (have/are?) lexical closures which save their environment and the local variable declaration isn't in the environment yet, so it doesn't get it])[/QUOTE] It's a local variable. What did you expect? Implicit forward referencing for local variables makes no sense at all be it Lua or otherwise. [QUOTE=yakahughes;27416806]The way C++ does it (requiring only declarations above their use instead of the actual definition which can be anywhere) allows you to do stuff which would otherwise be more difficult which I don't care to go into now.[/QUOTE] Actually that's not really true as modern languages often let you choose or compensate for it in some other way. For example, in C# you can use the P/invoke feature to separate interface from implementation as with header files, but it's only really needed for interfacing with C because you can link directly with any .NET assembly at build-time. In D you can choose to declare but not define symbols and it works exactly like C and C++ (D uses the same linking model). This is probably the most common way to facilitate C/C++ interop and separation of interface from implementation, also seen in many BASIC dialects. In other words, having a proper module system does not mean you cannot benefit from separating declaration and definition, it just means you can implicitly forward reference, and choose to have declaration and definition together while still being able to link cross-module.
People please don't laugh, but how can I make this shorter and not as ugly? [csharp] if(game.equals("Call of Duty")){ actualGame = "cod"; } else if (game.equals("Call of Duty 2")){ actualGame = "cod2"; } else if (game.equals("Call of Duty 4: Modern Warfare")){ actualGame = "cod4"; } else if (game.equals("Call of Duty: World at War")){ actualGame = "codwaw"; } else if (game.equals("Call of Duty: Black Ops")){ actualGame = "codbo"; } else if (game.equals("Counter-Strike 1.6")){ actualGame = "cs"; } else if (game.equals("Counter-Strike: Source")){ actualGame = "cssource"; } else if (game.equals("Day of Defeat")){ actualGame = "dod"; } else if (game.equals("Day of Defeat Source")){ actualGame = "dodsource"; } else if (game.equals("Half Life 2: Deathmatch")){ actualGame = "halflife2"; } else if (game.equals("Team Fortress 2")){ actualGame = "tf2"; } [/csharp] Thanks. (This is Java, by the way)
[url=http://download.oracle.com/javase/7/docs/api/java/util/Hashtable.html]java.util.Hashtable<String, String>[/url] Associate each name with the abbreviation, then you can check if the key is present in the hashtable and if so, simply get the abbreviation from it.
With gcc, how can I compile a set of source files to a static library? I've figured out how to compile into a shared library, and that way I don't have to declare a main() function, but I can't find how to compile to a static library. Here's my current build script: [code] gcc -g -std=c99 -shared -o bin/kari.lib -Iinc `find src/. | grep \\.c$ | perl -e 'while(<>){chomp;print"$_ "}'` gcc -g -o bin/ikari -Iinc repl/*.c bin/kari.lib [/code]
[QUOTE=pro ruby dev;27426739]With gcc, how can I compile a set of source files to a static library? I've figured out how to compile into a shared library, and that way I don't have to declare a main() function, but I can't find how to compile to a static library. Here's my current build script: [code] gcc -g -std=c99 -shared -o bin/kari.lib -Iinc `find src/. | grep \\.c$ | perl -e 'while(<>){chomp;print"$_ "}'` gcc -g -o bin/ikari -Iinc repl/*.c bin/kari.lib [/code][/QUOTE] Check [url=http://www.adp-gmbh.ch/cpp/gcc/create_lib.html]this[/url] out.
[QUOTE=sim642;27427406]Check [url=http://www.adp-gmbh.ch/cpp/gcc/create_lib.html]this[/url] out.[/QUOTE] :saddowns: You need to compile every file separately
Sorry, you need to Log In to post a reply to this thread.