Uses of C++? Tips for a beginner/intermediate coder?
38 replies, posted
I'm learning C++ currently and I have three questions for the elite programmers of FacePunch:
[b]
1. What can I use C++ for?
2. Tips for a beginner/intermediate programmer to further expand his/hers knowledge on the language?
3. What is a <static_cast> and a <reinterpret_cast>
[/b]
Thanks!
You can do anything in C++
Try SFML and doing some game programming
no fucking clue lol
A programming language is really only limited by the libraries that are available for it.
When I was younger I used to think that the language was the most "Desirable" to use for creating software, since a lot of games were made with it, but a lot can be made with pretty much any language.
I can't really come up with any examples of something that can't be made with c++.
As for your second point, practice and personal projects I always find help learning a language.
[editline]10th September 2015[/editline]
And for your third question:
[url]http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used[/url]
Looking at job advertisements in my country one would think C++ is completely useless and dead.
1. you can use c++ for about anything, but there's many things you would not prefer to use C++ for
2. flee before its too late
3. [url]http://stackoverflow.com/questions/103512/in-c-why-use-static-castintx-instead-of-intx[/url] might help
c++ is a ten ton hammer. it can do basically everything, and if you code it right, very fast and efficiently, but productivity is pretty bad compared to other languages. generally people only use it when they really have to (performance), so that's why it's used a lot in games and other performance hungry applications these days.
I used to make various applications to rename/manage files and do various math calculations. If you want to make GUI applications I'd suggest you look into [URL="https://www.qt.io/qt-framework/"]Qt framework[/URL]. Other than that, SFML comes to mind if you're into games development. I'd also suggest you look into [URL="http://www.boost.org/"]Boost[/URL].
Static casts uses the compiler to convert one variables data type to another. Reinterpret casts take the bits that make up that variables data and shove it into another data type. Don't ever use the second unless you know exactly what is going to happen. It is also machine dependent due to its nature so try avoiding its use at any cost.
I am a beginner C++ programmer as my first language and may soon have your problem. Perhaps looking into third party libraries like Windows?
I know this is a necro but for a good reason!
Is C++ like a "best of both worlds" of OOP and C? As in OOP concepts but also has C stuff like structs, pointers, enums etc.
I recently started using Java again and I realized that it can be annoying not having structs or pointers.
[QUOTE=ashxu;48794133]I know this is a necro but for a good reason!
Is C++ like a "best of both worlds" of OOP and C? As in OOP concepts but also has C stuff like structs, pointers, enums etc.
I recently started using Java again and I realized that it can be annoying not having structs or pointers.[/QUOTE]
I mean, pretty much. C++ is most generally described as an extension of C that adds a lot of the higher-level programming language features. Usually with a higher-level language like Java you won't care about having reference types, unless, like Rocket said, you're doing something gnarly or wrong.
Really, if you're doing systems programming, that's where C++ shines, because you actually care about a more hands-on approach to memory management. But not giving a shit about managing memory (within reason) is a big draw to languages like Java. C++ is often a good starting point because once you branch out to C#/Java you really appreciate a lot of what those development environments give you for free.
[QUOTE=Rocket;48794402]If you're in a position where you want to use pointers in Java, you're either interfacing with a native library (try using JNI!) or you're doing something wrong.
(C# has both pointers and structs if you [i]really[/i] want them)[/QUOTE]
[QUOTE=Protocol7;48794428]I mean, pretty much. C++ is most generally described as an extension of C that adds a lot of the higher-level programming language features. Usually with a higher-level language like Java you won't care about having reference types, unless, like Rocket said, you're doing something gnarly or wrong.
Really, if you're doing systems programming, that's where C++ shines, because you actually care about a more hands-on approach to memory management. But not giving a shit about managing memory (within reason) is a big draw to languages like Java. C++ is often a good starting point because once you branch out to C#/Java you really appreciate a lot of what those development environments give you for free.[/QUOTE]
dunno, was just working on a method that i wanted to return a string for ease of use however circumstances changed and I needed to also get an int. I ended up just creating another object to hold the data.
Been doing programming on and off throughout uni, C isn't too bad and I like certain things about it but after not doing Java for ages, doing C and then coming back to Java, I appreciate how much Java just does for you.
Might give C++ a shot down the road.
[QUOTE=Rocket;48794552][...] Or, if I was using C#, I'd use the out keyword. Or an anonymous object. [...][/QUOTE]
I know how to use anonymous types in LINQ queries and lambdas with inferred type, but how do you use them as normal return values without resorting to the (much slower) [I]dynamic[/I]?
[QUOTE=Tamschi;48809977]I know how to use anonymous types in LINQ queries and lambdas with inferred type, but how do you use them as normal return values without resorting to the (much slower) [I]dynamic[/I]?[/QUOTE]
I too am interested in this, I don't think you would because it's anon.. Doesn't the compiler generate the type and you don't have access to it?
In C++ if you want to crate a function that "returns" two values, you can have an additional argument that takes a reference to a preexisting object and have that function change that object. Like this:
[code]int process(int &arg) {
arg = 42;
return 1;
}[/code]
You can do this for any data type. Just call the function like this:
[code]int i = 0;
int j = process(i);
[/code]
I will be 42 and J will be 1. Easy Peasy workaround for when you need to "return" two values.
Even better: You can pass a pair. A pair in C++ is something added in the <utilities> header. It is a container that holds 2 different values. You can define the function like this:
[code]#include <utilities>
#include <string>
using namespace std;
pair<string, int> func(string s, int i) {
//process string and int
return make_pair(s, i);
}
int main() {
pair<string, int> p = func("dick", 42);
}[/code]
I imagine you can do the same with containers like arrays, vectors, lists, deques, and the likes, but pairs are easy to use and great if you only need two objects.
You can access the first and second element with p.first and p.second
To sum up : in C++ if you want to create a function that "returns" several values, you make a function that returns an object.
I'm far enough into my pursuit of knowladge to start worrying about this. I've been learning c++ for at least a couple of months and I believe I am ready to start learning how to make things other than fucking console applications. I don't by any means expect to make cool shit in a short span of time, but I do not want to wait any longer to start learning, or I fear I will get bored by the slow paced book learning I'm doing now, you know?
I've always wanted to learn how to make some sort of game. I want to start with 2d graphics, because I feel it's a good starting point and I enjoy 2d games. Here's what I'm looking for:
-Must support C++. It's currently the only language I have any kind of in-depth knowlage about and I am not ready to learn another language
-no preference on platform other than windows support must be present.
-i do not want to have to learn multiple libraries, so something that has plenty of general 2d capacity is preferred. I don't care if it's harder to learn than some shitty library that can only do a couple of things, I know it's better to put in the effort now.
-a link to documentation or any quality tutorials would make me smile.
I'll leave the rest for the more knowladgeable to help steer me into the right direction, just keep in mind I am self-taught.
Many thanks!
[QUOTE=TeamEnternode;48818988]I'm far enough into my pursuit of knowladge to start worrying about this. I've been learning c++ for at least a couple of months and I believe I am ready to start learning how to make things other than fucking console applications. I don't by any means expect to make cool shit in a short span of time, but I do not want to wait any longer to start learning, or I fear I will get bored by the slow paced book learning I'm doing now, you know?
I've always wanted to learn how to make some sort of game. I want to start with 2d graphics, because I feel it's a good starting point and I enjoy 2d games. Here's what I'm looking for:
-Must support C++. It's currently the only language I have any kind of in-depth knowlage about and I am not ready to learn another language
-no preference on platform other than windows support must be present.
-i do not want to have to learn multiple libraries, so something that has plenty of general 2d capacity is preferred. I don't care if it's harder to learn than some shitty library that can only do a couple of things, I know it's better to put in the effort now.
-a link to documentation or any quality tutorials would make me smile.
I'll leave the rest for the more knowladgeable to help steer me into the right direction, just keep in mind I am self-taught.
Many thanks![/QUOTE]
SDL or SFML would be perfect for you.
I use SDL myself. Good tutorial here: [url]http://lazyfoo.net/SDL_tutorials/[/url]
Dunno any good SFML tuts.
SFML is arguably more easier as its more modern and a lot more shits done for you so a lot of people use that instead of SDL, which is C styled because its written in C (although works perfectly with C++).
SDL and that tutorial is how I learned C++ myself, actually.
[QUOTE=awcmon;48819026]SDL or SFML would be perfect for you.
I use SDL myself. Good tutorial here: [url]http://lazyfoo.net/SDL_tutorials/[/url]
Dunno any good SFML tuts.
SFML is arguably more easier as its more modern and a lot more shits done for you so a lot of people use that instead of SDL, which is C styled because its written in C (although works perfectly with C++).
SDL and that tutorial is how I learned C++ myself, actually.[/QUOTE]
[url]http://lazyfoo.net/tutorials/SDL/index.php[/url]
?
[QUOTE=TeamEnternode;48819423][url]http://lazyfoo.net/tutorials/SDL/index.php[/url]
?[/QUOTE]
Oh yeah woops, that one, the SDL2 one. I accidentally sent the SDL1.2 ones. My bad.
[editline]3rd October 2015[/editline]
man, I remember when SDL2.0 was first introduced
it was fucking great
[editline]3rd October 2015[/editline]
oh remember to check out SFML tho. I think most people prefer that over SDL.
[editline]3rd October 2015[/editline]
[url]https://github.com/SFML/SFML-Game-Development-Book[/url]
i think this might be worth checking out, but idk how good/bad it is
[QUOTE=TeamEnternode;48819423][url]http://lazyfoo.net/tutorials/SDL/index.php[/url]
?[/QUOTE]
Man I wish his website didn't look so terrible
I tried SFML once
I got as far as not figuring out why it wouldn't fucking work
Has similar steps to SDL but more fucking awful and nothing worked so I gave up.
Might try again if it's worth it and there's a tut that does a better job
[QUOTE=TeamEnternode;48820397]I tried SFML once
I got as far as not figuring out why it wouldn't fucking work
Has similar steps to SDL but more fucking awful and nothing worked so I gave up.
Might try again if it's worth it and there's a tut that does a better job[/QUOTE]
[url]http://www.sfml-dev.org/tutorials/2.0/start-vc.php[/url]
You checked out the official one on their page for winderps + visual studio?
It's pretty straight forward for most part, unless that's the one you used :v:
Well I used the Code::Blocks tut but yeah
[QUOTE=TeamEnternode;48820491]Well I used the Code::Blocks tut but yeah[/QUOTE]
You should try Visual Studio 2015. I used to be a Code::Blocks user too, mostly since my hard drive was too small for Visual Studio. But once I switched over, I never went back. Visual Studio is so much better imo.
I tried linking SFML and Code::Blocks again, piece of shit still won't work.
Errors: [code]||=== Build: Debug in SFMLTut (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|5|undefined reference to `sf::String::String(char const*, std::locale const&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|5|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|5|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|6|undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|7|undefined reference to `sf::Color::Green'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|7|undefined reference to `sf::Shape::setFillColor(sf::Color const&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|15|undefined reference to `sf::Window::close()'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|12|undefined reference to `sf::Window::pollEvent(sf::Event&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|18|undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|18|undefined reference to `sf::RenderTarget::clear(sf::Color const&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|19|undefined reference to `sf::RenderStates::Default'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|19|undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|20|undefined reference to `sf::Window::display()'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|9|undefined reference to `sf::Window::isOpen() const'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|5|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Users\Not Public\Desktop\SDLTUT\SFMLTut\main.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
obj\Debug\main.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\Users\Not Public\Desktop\SFML-2.3.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\Users\Not Public\Desktop\SFML-2.3.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\Users\Not Public\Desktop\SFML-2.3.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `sf::Shape::~Shape()'|
||=== Build failed: 20 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|[/code]
My linker order(building on debug):
[img]https://dl.dropboxusercontent.com/u/152440973/fuckingpos.PNG[/img]
Can ask for anything else I might have forgotton.
And no I'm not changing IDE's. If I can't get this piece of shit to work then SDL it is.
[QUOTE=TeamEnternode;48868337]
And no I'm not changing IDE's. If I can't get this piece of shit to work then SDL it is.[/QUOTE]
you don't have to be a cunt about not wanting to change IDE's. it was just a suggestion
and chances are if you can't get SFML to work, you won't be able to get SDL to either
lazyfoo has a section on how to get SDL working with code::blocks
[url]http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php[/url]
it should be the same with sfml, and about any other library really, though the names will change of course
I wouldn't bother with SFML now. It could be just an isolated case for certain users, but I could not get the Audio module to work. Crashes, sometimes audio played, sometimes it didn't, and when I asked about it on the forums, I was told that this is a known issue, it wasn't getting fixed anytime soon, and I had to use SDL's audio library instead. If you're going to use SDL's audio, why not just use SDL entirely... So that is what I do now.
EDIT:
Also, people still use code::blocks? :vomit:
But I did get SDL to work
It's just fucking SFML
I use it because it's lightweight. I see the appeal in VS and other IDEs, but...
[QUOTE=TeamEnternode;48872634]I use it because it's lightweight. I see the appeal in VS and other IDEs, but...[/QUOTE]
I can see that :v:
VS itself runs decently fast now, but installing and uninstalling the thing...
[QUOTE=Trebgarta;48871455]What's wrong with code::blocks?
I'm not using/want to use, it's just my friends at university are made to use them in class, so normally they use at home for homeworks/projects too, I want to let them know now if there is a problem and get accustomed to other means too.[/QUOTE]
For me, it was mostly just that Code::Blocks felt so outdated and strange to use/operate. The text editor included felt outdated to the point where I ended up using Sublime Text almost exclusively to actually write my code, and Code::Blocks only to compile. I don't think it's necessarily bad though.
For me, the biggest change going from Code::Blocks to Visual Studio was getting used to the fact that Visual Studio had a shit ton more options and I would get lost sometimes when I tried to include a library in my project. Even then, it was fairly similar in operation (to add a new library anyways). In both you just put in the directories to the includes and headers so the thing knew where to find the files, and then link against the libraries somewhere.
I actually like using GCC/G++ more than using Microsoft's C++ Compiler, and I also liked that Code::Blocks actually supported C. Visual Studio's C support just goes like "Well, you can compile C as C++. Have fun kid." But Visual Studio felt so good in other ways I switched.
tl;dr tho i wouldn't worry about your friends using Code::Blocks. I think it's actually better that they use something like Code::Blocks in order to get used to not having the luxury of insane good intelligent code completion when they're beginning to learn to code due to the possible risk of becoming "spoiled" on it. My only gripe with Code::Blocks is that it just feels so outdated.
[editline]10th October 2015[/editline]
initially i actually had a lot of ambivalence towards visual studio because I had a pretty bad experience with various versions of visual c++, but visual studio is great
Sorry, you need to Log In to post a reply to this thread.