-
January 12th, 2009, 02:04 AM
#1
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??
"What comes around, goes around"
-
January 12th, 2009, 03:13 AM
#2
Re: compling issues - const issue
Fixed, just add a default empty constructor.
"What comes around, goes around"
-
January 12th, 2009, 08:32 AM
#3
Re: compling issues - const issue
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.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
January 12th, 2009, 08:37 AM
#4
Re: compling issues - const issue
Originally Posted by Fraham
Which compiler are you using?
Read the end of my first post ie.
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)
"What comes around, goes around"
-
January 12th, 2009, 09:05 AM
#5
Re: compling issues - const issue
Your posted code compiles with no errors when using Visual Studio 2008.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
January 12th, 2009, 09:43 AM
#6
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?
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
January 12th, 2009, 09:51 AM
#7
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.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
January 12th, 2009, 09:55 AM
#8
Re: compling issues - const issue
Originally Posted by Graham
Are you sure that what you posted is the entire code that generated the error?
yep
"What comes around, goes around"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|