Namespace confusion.

This is a discussion on Namespace confusion. within the C++ Programming forums, part of the General Programming Boards category; Hello all... In the god old times when a few compilers supported namespaces you could put incomplete declarations in headers ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    Namespace confusion.

    Hello all...
    In the god old times when a few compilers supported namespaces you could put incomplete declarations in headers file, e.g.:

    class ostream;
    class someclass {
    ostream* ptr
    };

    Now the problem is that when I try to write:

    class std::ostream;
    class someclass {
    std::ostream* ptr;
    };

    the compiler (g++ 3.4) gives me a warning that it expects a type-name in the line with "class std::ostream;". What to do?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    You can't declare a class like that; if you want to declare the class 'ostream' within the namespace called 'std', then you do:
    Code:
    namespace std
    {
       class ostream;
    }
    The easiest solution is, of course, just to include the <iostream> header
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. namespace problem
    By DL1 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2008, 01:10 PM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 03:45 AM

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