Thread: compling issues - const issue

  1. #1
    Spam is Good
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    37

    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??
    Last edited by coletek; 01-12-2009 at 12:57 AM.
    "What comes around, goes around"

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Just give TestPrint an user-defined default constructor that does nothing, and it will work.

    Code:
    class TestPrint {
    public:
      TestPrint() {}
    };
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  2. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 01:06 PM
  3. Another problem with templates
    By robatino in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2006, 04:32 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. "error: incomplete type is not allowed"
    By Fahrenheit in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2005, 09:52 PM