Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: compu on November 16, 2013, 06:09:32 pm

Title: [Ndless/C++] Problems with inheritance
Post by: compu on November 16, 2013, 06:09:32 pm
I am trying to make a C++ class for Nspire I/O that works like the standard iostream class.
For this purpose, I have the class console (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/console.hpp), which is just a simple C++ wrapper for Nspire I/O, and the class nio_base (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/nio_base.hpp), that provides stuff from the standard ios_base (http://www.cplusplus.com/reference/ios/ios_base/) class.
The class iostream (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/iostream.hpp) inherits from both console and nio_base, so we can use the <<, >> operators and more for Nspire I/O consoles.

My problem is, when I am trying to set the field width with the function width() (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/nio_base.cpp#L191) from nio_base to 10, it stays 0 when I read it from inside the iostream class (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/iostream.cpp#L84).
Also, using setf() (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/nio_base.cpp#L30) crashes the emulator.

This is the code I'm trying to run. (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/demo/demo.cpp)
Basically everything works, except the field width change and the unsetf/setf stuff.

The code works fine on the other branch (https://github.com/compujuckel/nspire-io/tree/cpp-support/niostream) where the nio_base stuff is integrated into iostream, but I wanted to separate it so I don't have to duplicate the code for RS232 communcication.

Download the code (https://github.com/compujuckel/nspire-io/archive/cpp-dev.zip)
To build, make lib install in the root dir
make lib install demo in niostream
Make sure there are no old versions of Nspire I/O in your Ndless SDK.
Title: Re: [Ndless/C++] Problems with inheritance
Post by: Levak on November 17, 2013, 07:02:41 pm
The class iostream (https://github.com/compujuckel/nspire-io/blob/cpp-dev/niostream/iostream.hpp) inherits from both console and nio_base, so we can use the <<, >> operators and more for Nspire I/O consoles.
I'm not a C++ master, but multiple inheritance has been a problem since beginning of POO, hasn't it ?

I know Java makes it different with interfaces, but what I learnt in C++ always made me feel this was impossible to achieve cleverly.
Title: Re: [Ndless/C++] Problems with inheritance
Post by: ExtendeD on March 17, 2014, 02:26:41 pm
compu, were you able to fix that one?
Title: Re: [Ndless/C++] Problems with inheritance
Post by: bb010g on March 17, 2014, 09:57:43 pm
Isn't this fixable with virtual inheritance? (I don't C++ much, so I'm not sure.)
Title: Re: [Ndless/C++] Problems with inheritance
Post by: Vogtinator on April 01, 2014, 01:58:45 pm
I would check myself, but github gives me "500 internal server error"...
- bFLT? (Needed)
- Compile flags? (At least -fpic -mlong-calls)
- If you run elf2flt manually, what's the output?