compling issues - const issue
Code:
#include <iostream>
class TestPrint
{
public:
void Print()
{
std::cout << "TestPrint" << std::endl;
}
void Print() const
{
std::cout << "const TestPrint" << std::endl;
}
void Print() volatile
{
std::cout << "volatile TestPrint" << std::endl;
}
void Print() const volatile
{
std::cout << "const volatile TestPrint" << std::endl;
}
};
int main(int argc, char* argv[])
{
TestPrint normal_test;
normal_test.Print();
const TestPrint const_test;
const_test.Print();
volatile TestPrint volatile_test;
volatile_test.Print();
const volatile TestPrint const_volatile_test;
const_volatile_test.Print();
}
Code:
coletek@spamisgood:~/sandbox/cc> g++ eg.cc
eg.cc: In function ‘int main(int, char**)’:
eg.cc:34: error: uninitialized const ‘const_test’
eg.cc:40: error: uninitialized const ‘const_volatile_test’
What do I initialize them to tho??
Re: compling issues - const issue
Fixed, just add a default empty constructor.
Re: compling issues - const issue
Quote:
Originally Posted by
coletek
Fixed, just add a default empty constructor.
Which compiler are you using? That shouldn't make any difference because your class will have a default ctor provided for it by the compiler.
Re: compling issues - const issue
Quote:
Originally Posted by Fraham
Which compiler are you using?
Read the end of my first post ie.
Quote:
Originally Posted by coletek
Code:
coletek@spamisgood:~/sandbox/cc> g++ eg.cc
eg.cc: In function ‘int main(int, char**)’:
eg.cc:34: error: uninitialized const ‘const_test’
eg.cc:40: error: uninitialized const ‘const_volatile_test’
For more info on what version:
Code:
coletek@spamisgood:~> g++ -v
Using built-in specs.
Target: powerpc-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu11' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --disable-softfloat --enable-secureplt --enable-targets=powerpc-linux,powerpc64-linux --with-cpu=default32 --with-long-double-128 --enable-checking=release --build=powerpc-linux-gnu --host=powerpc-linux-gnu --target=powerpc-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11)
Re: compling issues - const issue
Your posted code compiles with no errors when using Visual Studio 2008.
Re: compling issues - const issue
It's the version number I was after (I somehow managed to completely omit the word "version" from the question).
Are you sure that what you posted is the entire code that generated the error?
Re: compling issues - const issue
Interesting - Comeau fails it with the same errors. Presumably implicit default ctors are not considered wrt const objects. I'll see if I can find the relevant section of the standard.
Re: compling issues - const issue
Quote:
Originally Posted by Graham
Are you sure that what you posted is the entire code that generated the error?
yep