Author Topic: [Ndless/C++] Problems with inheritance  (Read 4659 times)

0 Members and 1 Guest are viewing this topic.

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
[Ndless/C++] Problems with inheritance
« 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, which is just a simple C++ wrapper for Nspire I/O, and the class nio_base, that provides stuff from the standard ios_base class.
The class iostream 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() from nio_base to 10, it stays 0 when I read it from inside the iostream class.
Also, using setf() crashes the emulator.

This is the code I'm trying to run.
Basically everything works, except the field width change and the unsetf/setf stuff.

The code works fine on the other branch 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
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.

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: [Ndless/C++] Problems with inheritance
« Reply #1 on: November 17, 2013, 07:02:41 pm »
The class iostream 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.
« Last Edit: November 17, 2013, 07:04:38 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: [Ndless/C++] Problems with inheritance
« Reply #2 on: March 17, 2014, 02:26:41 pm »
compu, were you able to fix that one?
Ndless.me with the finest TI-Nspire programs

Offline bb010g

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 428
  • Rating: +22/-1
  • I do stuff
    • View Profile
    • elsewhere on the net
Re: [Ndless/C++] Problems with inheritance
« Reply #3 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.)
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless/C++] Problems with inheritance
« Reply #4 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?