Re: 'const' ignored when compiling in linux
* none, on 19.05.2010 19:33:
Christian Hackl wrote:
none ha scritto:
#include <vector>
class Image2D {
public:
void test() const {
con.push_back(234);
}
private:
std::vector<int> con;
};
int main(){
Image2D img;
// test();
return 0;
}
compiles fine on ubuntu linux using gcc 4.4.1.
It should not. Are you sure this is exactly the same code that you
actually compiled? If it really is the same, then you must be invoking
the compiler with some wrong options.
These are the options that I use:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -s -lX11 -Dcimg_use_xshm
-lXext -Dcimg_use_xrandr -lXrandr -O3 -fpermissive -march=nocona -m64
-ffast-math -funroll-loops -finline-functions")
Don't know, the "permissive" thing seems ungood, but I don't know what it does.
I suggest check it out.
It really shouldn't compile.
Are you sure that that's exactly the code you're trying to compile? E.g.,
templating can make things compile when they're not actually used. And that's a
feature, not a bug... :-)
There are plenty of other stuff that is not caught using gcc. As an
example I have this:
template <typename A, typename J>
class Producer {
public:
typedef J JobType;
const unsigned int Dimension = JobType::Dimension;
..
...
which compiles fine when using gcc. But in VS I need to a the static
keyword to make it compile:
const static unsigned int Dimension = JobType::Dimension;
That sounds like a C++0x thing in g++.
Add options '-std=c++98 -pedantic -ansi'.
Or you may have to adjust, I'm just writing this from memory.
Cheers & hth.,
- Alf (still practical mode)
--
blog at <url: http://alfps.wordpress.com>