Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualCornstalks

Posted 20 April 2013 - 03:07 PM

(basic_istream and basic_ostream virtually inherit from basic_stream, and basic_iostream inherits from both basic_istream and basic_ostream)

 

I'm a bit rusty on my C++ now, but how does basic_iostream avoid having two sets of internal stream state if it inherits from basic_stream twice? (Or maybe two sets of underlying state is not a problem?).

By virtual inheritance (basic_istream virtually inherits from basic_ios, and basic_ostream virtually inherits from basic_ios). Here are the definitions of these classes:

 

// Note: I'm omitting the template stuff for simplicity
 
// Section 27.7.2.1 of the C++ standard, for the curious
class basic_istream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.3.1 of the C++ standard, for the curious
class basic_ostream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.2.5 of the C++ standard, for the curious
class basic_iostream : // This works fine, since basic_istream and basic_ostream virtually inherit from basic_ios
    public basic_istream,
    public basic_ostream {
  /* ... */
};

Also, sorry, I meant basic_ios instead of basic_stream in that post (which I've fixed now).


#3Cornstalks

Posted 20 April 2013 - 03:05 PM

(basic_istream and basic_ostream virtually inherit from basic_stream, and basic_iostream inherits from both basic_istream and basic_ostream)

 

I'm a bit rusty on my C++ now, but how does basic_iostream avoid having two sets of internal stream state if it inherits from basic_stream twice? (Or maybe two sets of underlying state is not a problem?).

By virtual inheritance (basic_istream virtually inherits from basic_ios, and basic_ostream virtually inherits from basic_ios). Here are the definitions of these classes:

 

// Note: I'm omitting the template stuff for simplicity
 
// Section 27.7.2.1 of the C++ standard, for the curious
class basic_istream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.3.1 of the C++ standard, for the curious
class basic_ostream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.2.5 of the C++ standard, for the curious
class basic_iostream : // This works fine, since basic_istream and basic_ostream virtually inherit from basic_ios
    public basic_istream,
    public basic_ostream {
  /* ... */
};

#2Cornstalks

Posted 20 April 2013 - 03:05 PM

(basic_istream and basic_ostream virtually inherit from basic_stream, and basic_iostream inherits from both basic_istream and basic_ostream)

 

I'm a bit rusty on my C++ now, but how does basic_iostream avoid having two sets of internal stream state if it inherits from basic_stream twice? (Or maybe two sets of underlying state is not a problem?).

By virtual inheritance (basic_istream virtually inherits from basic_ios, and basic_ostream virtually inherits from basic_ios). Here are the definitions of these classes:

 

// Note: I'm omitting the template stuff for simplicity
 
// Section 27.7.2.1 of the C++ standard, for the curious
class basic_istream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.3.1 of the C++ standard, for the curious
class basic_ostream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.2.5 of the C++ standard, for the curious
 
class basic_iostream : // This works fine, since basic_istream and basic_ostream virtually inherit from basic_ios
    public basic_istream,
    public basic_ostream {
  /* ... */
};

#1Cornstalks

Posted 20 April 2013 - 03:04 PM

(basic_istream and basic_ostream virtually inherit from basic_stream, and basic_iostream inherits from both basic_istream and basic_ostream)

 

I'm a bit rusty on my C++ now, but how does basic_iostream avoid having two sets of internal stream state if it inherits from basic_stream twice? (Or maybe two sets of underlying state is not a problem?).

By virtual inheritance (basic_istream virtually inherits from basic_ios, and basic_ostream virtually inherits from basic_ios). Here are the definitions of these classes:

// Note: I'm omitting the template stuff for simplicity
 
// Section 27.7.2.1 of the C++ standard, fo the curious
class basic_istream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.3.1 of the C++ standard, fo the curious
class basic_ostream :
    virtual public basic_ios { // Notice the virtual inheritance
  /* ... */
};
 
// Section 27.7.2.5 of the C++ standard, fo the curious
 
class basic_iostream : // This works fine, since basic_istream and basic_ostream virtually inherit from basic_ios
    public basic_istream,
    public basic_ostream {
  /* ... */
};

PARTNERS