compling issues - const issue

This is a discussion on compling issues - const issue within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> class TestPrint { public: void Print() { std::cout << "TestPrint" << std::endl; } void Print() const { ...

  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-11-2009 at 11:57 PM.
    "What comes around, goes around"

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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, 04:34 PM
  2. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 12: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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21