CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    30

    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"

  2. #2
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    30

    Re: compling issues - const issue

    Fixed, just add a default empty constructor.
    "What comes around, goes around"

  3. #3
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: compling issues - const issue

    Quote Originally Posted by coletek View Post
    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


  4. #4
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    30

    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)
    "What comes around, goes around"

  5. #5
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    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

  6. #6
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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


  7. #7
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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


  8. #8
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    30

    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
    "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
  •  





Click Here to Expand Forum to Full Width

Featured