SFML community forums
Help => Graphics => Topic started by: KasHKoW on August 16, 2011, 10:52:46 pm
-
I have a class that inherits public properties from sf::RenderWindow. What's wrong with it if it can't use basic constructor's like the 2 argument sf::VideoMode, string one?
Also i'm about to peak at the RenderWindow.cpp source code, but doesn't anyone know if I can just make my own constructor like that and use the variables used in the orig. constructor etc. Basically make a copy... but I still don't know why the first one wouldn't work if i'm using it correctly. Also this is my only error in compiling this one header with three source files.
-
What's wrong with it if it can't use basic constructor's like the 2 argument sf::VideoMode, string one?
Could you describe the problem more clearly? What doesn't work exactly? Please provide a short code.
Same for the other problem, I don't understand your description ;)
-
hpp file
class _2deWindow : public sf::RenderWindow {
//couple variables
public:
//couple functions
};
source file
_2de::_2deWindow App(sf::VideoMode(800,600,32), "Boundaries Test");
error
BoundTests.cpp: In function βint main()β:
BoundTests.cpp:8: error: no matching function for call to β_2de::_2deWindow::_2deWindow(sf::VideoMode, const char [16])β
_2de.hpp:51: note: candidates are: _2de::_2deWindow::_2deWindow()
_2de.hpp:45: note: _2de::_2deWindow::_2deWindow(const _2de::_2deWindow&)
I have no constructors what so ever. As you can see, which I just noticed, it's noticing it as a function which is weird.
-
Constructors are not inherited. You have to write your own, and forward the arguments to the base class via initializer list.
This should be explained in your C++ book...
-
I haven't read one. I don't really plan on it either.
They kind of turn me off from coding. I want to read effective c++/accelerated c++, but I really haven't got the time. I'm using cprogramming.com && cplusplus.com's tutorials which are pretty nice.
-
class _2deWindow : public sf::RenderWindow {
public:
_2deWindow(sf::VideoMode a, std::string title):sf::RenderWindow(a,title){}
};
Something like that should work
-
I think books are really worth the time, you can't learn C++ effectively by internet tutorials. At least I haven't seen one that covers C++ deeply enough and that doesn't neglect important background information.
-
I haven't read one. I don't really plan on it either.
They kind of turn me off from coding. I want to read effective c++/accelerated c++, but I really haven't got the time. I'm using cprogramming.com && cplusplus.com's tutorials which are pretty nice.
I'd recommend trying one, I started with Beginning C++ Game Programming, it's essentially just a C++ beginners book disguised as game coding.
I noticed that I improved and learnt at a much faster rate after swapping to books compared to doing online tutorials. At the very least it's easier than alt-tabbing to compare your code with the examples.
But at least you've already found cplusplus.com, I think it's the best online reference available. Keep it handy when dealing with the STL. :D
-
I think books are really worth the time
Yes, absolutely! Take this advice seriously into consideration. Moreover, AC++ is a very good book (good example, good approach, etc..)
cplusplus.com, I think it's the best online reference available.
gloups (http://programmers.stackexchange.com/questions/88241/whats-wrong-with-cplusplus-com) (ok, it isn't the point of the discussion but...)
-
gloups (http://programmers.stackexchange.com/questions/88241/whats-wrong-with-cplusplus-com) (ok, it isn't the point of the discussion but...)
Oh wow. Thanks for that, I redact my earlier statement. And now I have to go hunting for a new reference site.
-
I would recommend this one if you're not afraid of raw stuff : http://www.dinkumware.com/manuals/#Standard%20C++%20Library . It's not the easiest, I agree, but it seems complete and correct (I never heard of problem on this reference site to be precise).
-
Yeah The books I was reading was Game Programming All in One third edition; Accelerated C++; cplusplus.com C++ Language Tutorial for quick reference. I haven't completely finished any of them yet. The first two not even close lol. I might start looking at them little by little now.
EDIT: I will take a look at that one.
-
I noticed that I improved and learnt at a much faster rate after swapping to books compared to doing online tutorials. At the very least it's easier than alt-tabbing to compare your code with the examples.
But at least you've already found cplusplus.com, I think it's the best online reference available. Keep it handy when dealing with the STL. :D
I've learned the fastest by simply using tutorials writing code, reading others code, and doing major refactoring implementing a bunch of new ways that just did the same stuff as the old ways faster and better with conciseness in mind.
also learning a new language, but not even writing in it, can augment your currently known and in use languages a lot.
-
One problem with cplusplus.com is also that it contains no information about C++0x nor the TR1. I have mostly used MSDN to lookup library features of the new C++ standard, although the navigation on the site is not the best one.
-
class _2deWindow : public sf::RenderWindow {
public:
_2deWindow(sf::VideoMode a, std::string title):sf::RenderWindow(a,title){}
};
Something like that should work
That's really nice. I thought I understood how it worked but now I'm confused.. The single colon ":sf::RenderWindow(...)...{}" part is confusing. did you mean a comma and to keep it in the first list or arguments or is that a feature I'm not even aware of?
-
The single colon indicates the start of the initialiser list. Like so:
Constructorname(parameters) : namespace::baseConstrustorname(baseconstructorParameters)
{
body
}
the syntax is similar to how you declare an inherited class:
classname : public baseclass
But they only work for constructors, base constructors and member variables.
What you're doing is passing your argument title, to the normal RenderWindow constructor, that way all the data that Renderwindow normally takes care of(which you also inherited) is still initialised properly.
Look up "initialiser lists" for more info, you can do other stuff with them as well, such as initialising variables more efficiently.
-
Wow, that's really cool. I finally got my own constructor working and it gives me a seg fault. Run it through gdb but at the same time just try that one.