Hello All
I have a compilation error in a very large program. We have managed to isolate the problem with the following test problem:
Code:
#include <vector>
#include <iostream>
using namespace std;
int main()
{
double* myPointer=NULL; // no error on this line
vector<double*> myVect(1,NULL); // error on this line
return 0;
}
Compiling this spits out the error:
Cannot convert 'int' to 'std::vector<double*>::value_type {aka double*}'
When I compile this on GNU gcc compiler version 4.5.1 I do not get this error. When I compile it on GNU gcc compiler version 4.7.1 I get the error.
Since the first reference to NULL works then we can conclude that NULL is defined and it can be used to initialize pointers. However when NULL is passed as an initialization to a std::vector container it is no longer type compatible.
First Question: Is this a bug in the 4.7.1 compiler or did the compiler change to conform to some standard that does not allow vector's to initialized to NULL.
I know there is an easy fix. However I have a large amount of code that has 8000+ instances of the work 'NULL'. I do not want to change all those instances to something like '(type*)0' just to find out later that this is a compiler error.
Second Question: Is there a simple work around so I do not have to change all those instances of NULL?
I know that I can stick with the 4.5.1 version of gcc. However if this is a permanent change in the compiler then I want to make the code work in future versions of g++.
Thanks
Mike
No comments:
Post a Comment