Wednesday, December 8, 2010

a new compiler error

While I am currently trying to get KDE on Windows up to a releasable state again (nearly done ;-)), I found an interesting compiler error with the new Visual Studio version (2010):


...
class Andere;

class Klasse {
public:
Klasse() : bc(NULL, NULL){
}
private:
std::pair<Andere*, Andere*> bc;
};
...

Why could the above fail? Right, because NULL is not of type class Andere. (That works on the other compilers we have...)

6 comments:

Petr said...

Aren't you missing the template parameters in std::pair?

Kåre said...

Could it be that VisualStudio does not like "NULL".

http://www2.research.att.com/~bs/bs_faq2.html#null

Frank said...

It seems the blogging software ate your template arguments (because of the <, >)

SaroEngels said...

Ok, I fixed it, of course it ate the template parameters :-P

Anonymous said...

I would stick to Bjarne's advice:

http://www2.research.att.com/~bs/bs_faq2.html#null

Anonymous said...

C++0X have a new nullptr type for that, I think it is why. In other languages, real nulptr are a cool feature, not yet in C++, where they are somewhat as good as NULL, but in future version, it may be as good as in lua or so.

GCC 4.5 is also more selective when it come to accepting NULL. You can't do QString myString = NULL (be default) whilw ith previous versions, it worked. Now, I have to use "" in optional function parameter.