0

I'm using libsourcey lib for learning. I try to write a new class that inherit a class named Signal.

in libsourcey

template <typename RT> class Signal;
template <typename RT, typename... Args> class Signal<RT(Args...)> {...}

and my way

template <typename RT> class NewSignal;
template <typename RT, typename... Args> class NewSignal<RT(Args...)> : public Signal<RT(Args...)> {...}

but i can't access any property of class Signal, also attribute (although I modify attribute to public). Complier (eclipse) report: was not declared in this scope

Example

I have 2 class

class B

template<class RT> class B;

template<class RT, class... Args>
class B<RT(Args...)> {
public:
    B(int value = 0) : m_i(value) {}
    ~B() {}
    void print() {
        std::cout << "i = " << m_i << std::endl;
    }
    int m_i;
};

class A

template<class RT> class A;

template<class RT, class... Args>
class A<RT(Args...)> : public B<RT(Args...)> {
public:
    A(int value = 0) : B<RT(Args...)>(value) {}
    virtual ~A() {}
    void print() {
        std::cout << "i = " << 2 * m_i << std::endl;
    }
};

When build i get error enter image description here

and main.cpp

#include "Aclass.hpp"
#include "Bclass.hpp"

int main(int argc, char* argv[]) {
    B<void(void)> b(1);
    b.print();
    A<void(void)> a(2);
    a.print();
    return 0;
}

But when i change std::cout << "i = " << 2 * m_i << std::endl; in class A to std::cout << "i = " << 2 * B<RT(Args...)>::m_i << std::endl; then build done, no error.

Anyone explain why compiler report like this. How i can inherit Signal class. If not, have any solution? Thank for supporting.

twid
  • 6,368
  • 4
  • 32
  • 50
Trung Trinh
  • 57
  • 1
  • 7
  • 1
    *What* was not declared in scope? Do you need to use a namespace qualifier? – John Perry May 31 '18 at 09:28
  • @John Perry: example: _slots, _mutex (i changed to them from private to public in singal class). I added link of Signal class in my question. – Trung Trinh May 31 '18 at 09:30
  • You need to give an example of the code you're writing and the precise error message. – John Perry May 31 '18 at 09:32
  • Also, shouldn't `template class NewSignal;` inherit from `class Signal`? – John Perry May 31 '18 at 09:34
  • @JohnPerry: do you have any solution if don't use `template class NewSignal`; inherit from `class Signal`? I also will send example soon :) – Trung Trinh May 31 '18 at 10:41
  • No; I'm not inclined at the moment to download the package & try to make it work (I'm on vacation) but what you're writing makes me wonder if it isn't a class inheritance issue.Things like `_slots` and `_mutex` seem like class members, which the non-templated `NewSignal` can't access if it doesn't inherit from `Signal`. On the other hand, the templated `NewSignal` does inherit so if your problem is there, then that's a different issue. – John Perry May 31 '18 at 11:41
  • @JohnPerry I updated example. is my solution right? – Trung Trinh Jun 01 '18 at 07:21
  • my question the same [enter link description here](https://stackoverflow.com/questions/3277812/c-template-class-inheriting-another-template-class-with-a-template-specified-i) – Trung Trinh Jun 01 '18 at 07:55

0 Answers0