Results 1 to 4 of 4

Thread: Why doesn't this work (inheritance & namespaces)

  1. #1

    Thread Starter
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Why doesn't this work (inheritance & namespaces)

    This code gives an error ("illegal member initialization: 'ifstream' is not a base or member")
    Code:
    #include <fstream>
    
    namespace MyNamespace{
        class MyClass;
    }
    
    class MyNamespace::MyClass : public std::ifstream{
    public:
        MyClass() : std::ifstream() {}
    };
    but this code does not:
    Code:
    #include <fstream>
    using std::ifsream;
    
    namespace MyNamespace{
        class MyClass;
    }
    
    class MyNamespace::MyClass : public ifstream{
    public:
        MyClass() : ifstream() {}
    };
    What am I doing wrong?

    EDIT: I'm using MSVC 6
    Last edited by twanvl; Mar 16th, 2002 at 07:44 AM.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    using std::ifsream;
    Is this a typo, or exactly what was in your source file?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    The original code did say
    Code:
    using std::ifstream;
    I made a typo on this forum.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    MSVC6 behaves very strange sometimes.
    If you don't want to use a specific constructor of ifstream you can use the first method because you don't need to put ifstream into your constructor list.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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