Archive
C++ Renaissance: The “Going Native” Channel
Check out this post on Herb Sutter’s blog: it provides links to a new series of videos on MSDN all about native coding, particularly in C++. Enjoy!
New Look
As you may have noticed, I have changed the blog’s theme. Now, I know it’s not very original: Twenty Eleven is essentially WordPress’ theme of the year as far as I can see. But nonetheless, I think it looks nice
Anyway, the point is, I want to know your opinion. So let me know what you think of the new theme. Fill out out the form below or comment on this post!
Thanks,
Xander
New Theme Survey
Migrating to SFML 2.0
Many people have difficulty migrating from SFML 1.6 to 2.0. The fact is there are quite a few public interface changes and there are as yet no SFML 2.0 tutorials. I suggest you still use the 1.6 tutorials if you want to be guided through the learning process, and then make up the gap using either or both of the following
- the SFML 2.0 documentation (note that the documentation on the site is also slightly out of date, but you can create your own using the source and Doxygen)
- this thread delineating the changes in SFML 2.0
Scheduled Maintenance
The blog’s been quiet for quite a while now, for which I apologise. Basically, my work has dragged on longer than expected, but hopefully I’ll be able to continue soon.
But to the title of the post. My computer is becoming old and too hot, so I am upgrading one or two components and switching case. I also want to reinstall Windows, but there’s no point doing that until the hardware’s been changed. Why should you care? Well basically, I am meaning to upload some prebuilt SFML binaries, but to do so I want to install Visual C++ Express 2008 and 2010 in order to provide the widest range of development options I can. However, my computer is not in a fit state for extra junk right now and frankly I don’t want two of the same IDE on the primary desktop. Therefore, what I’ll do is run it off Virtual PC. Once again, however, I don’t want to get knee deep in that kind of thing until my desktop is new and improved.
Anyway, I hope you won’t lose interest in the mean time, and I’ll try not to keep you waiting too long!
Until then,
Xander
A Few Videos – At Last!
So I have now uploaded the videos on building SFML 2.0 with NMake and MinGW Make. At last! So they’ve now been embedded in the relevant articles:
Oh, and if you see any of my YouTube videos with [dpctd] on the end of the title, it means I have marked them as deprecated. In other words, I’ve decided there are enough mistakes in it that I want to rerecord and re-upload it. There will either be a new version already annotated in the old video, or at least, I’ll upload a new one soon.
Overloading Template Functions
Another little tip inspired by a question on cplusplus.com. How do we overload template functions? Well the answer is that we overload the template function in the same way as we would overload any other function.
template <class A> void foo()
{
}
template <class A> void foo(float f)
{
}
We do, however, have to be slightly more careful with specialised functions. If we overload a specialised function, the overload must match some overloaded version of the template.
template <class A> void foo()
{
}
template <class A> void foo(float f)
{
}
template<> void foo<int>() // allowed: matches the first template
{
}
template<> void foo<int>(float f) // allowed: matches the seconds template
{
}
template<> void foo<int>(const char*) // not allowed: does not match any template
{
}
Gaming!
I imagine quite a few of us on here are gamers, so here’s another funny comic from xkcd.com. Don’t worry – I promise not to bombard you with too many of these.
C++ Tip – this
You probably all know about the this pointer already, but I just answered a question about it on cplusplus.com, so I thought that I may as well post here while it’s at the forefront of my mind!
So this is a keyword which we can use inside a member function. It is a pointer to the instance of the class from which the member function was called. Still not sure? Check out the following example program.
#include <iostream>
class foo {
public:
void bar() { std::cout << this << std::endl; }
};
int main()
{
using namespace std;
foo foo1, foo2;
cout << "foo1\n" << &foo1 << endl;
foo1.bar();
cout << "foo2\n" << &foo2 << endl;
foo2.bar();
return 0;
}
This program yielded the following output for me.
foo1 0031F916 0031F916 foo2 0031F917 0031F917
For you, the actual numerical values of the addresses may be different, but the point is that the address of foo1 is the same as the value printed by foo1.bar() (which prints the this pointer) and the address of foo2 is the same as the value printed by foo2.bar().
So, if you couldn’t before, you can now hopefully understand what I mean when I say that the this pointer points to the instance of the class from which the member function was called.
Interesting Point: Notice that the address of foo1 is only 1 behind the address of foo2. We created the two variables on the same line as stack variables, so they are in adjacent memory locations. However, as the classes are effectively empty, the memory locations are in fact even consecutive (each instance takes only one space on the stack).
Notes
- Remember that this may only be used from inside member functions (think about it – it wouldn’t make much sense anywhere else)
- this cannot be used in a constructor’s initializer list, but it can be used in its body
- this can be used in a destructor’s body, but be careful as if the class is being destroyed you probably don’t want to go around handing its address out to other functions and variables
Videos on the Way
Sorry that I’m getting further and further behind on the videos. I have to do the ones for NMake and MinGW, redo the first SFML project ones and also record ones for Video Modes and Windowing and (soon!) Text and Fonts. In the mean time, enjoy the textual tutorials, and I’ll get the videos to you as soon as I can.
The problem is that my video editor will only export 1080p videos in AVC H264 format, which results in >1GB files which take all day to upload. Therefore I’m looking to do the final render in Expression Encoder instead, which will mean the quality is better (fewer compression passes) and also the file size is smaller.
Until then
-Xander
Real Programmers
We’ve all heard reference to these “real programmers” who, at best, code with a binary editor directly into machine code, and at worst find some way of manually magnetising the surface of the disk. Well here is an amusing comic from xkcd.com on the subject.
I have something else funny to show you as well. Here’s another picture. Sorry it’s not in the body of the post, but I’m not sure of the licensing, etc. If that link doesn’t work, try this one.


