HSDave Posted April 22, 2016 Report Share Posted April 22, 2016 Hi, I want to pass a sc_signal (the reference of one) of any type to a class as a CTOR-argument. Since i found out, that the &-Operator of the class sc_signal<T> is overloaded, so i don't get the reference of an sc_signal<T> object but instead i get a reference to an Object of type T. How am i supposed to pass an sc_signal<T> to a function or a class? Example-Code: #include <systemc.h> template<typename T> class TInput{ public: typedef sc_signal<T> &TMember; TInput(TMember member):member(member){} // some functions which use member private: TMember member; }; int sc_main(int argc, char** argv){ sc_signal<sc_uint<12> > signal1("signal1"); TInput<sc_uint<12> > input(signal1); // here is the problem, because &signal1 does not return return 0; // its own reference but a const reference to its member // so the compiler is telling me, that i want to call a function which does not exist } here is a link to sc_signal class of systemc lysium documentation http://www.iro.umontreal.ca/~lablasso/docs/SystemC2.0.1/html/classsc__signal.html especially this function operator const T & () const its implementation (of sc_logic) can be found under following link: http://www.lysium.de/docs/systemc-2.2/docs/html/sc__signal_8h-source.html 00132 operator const T& () const 00133 { return read(); } 00113 // read the current value 00114 virtual const T& read() const 00115 { return m_cur_val; } 00648 sc_dt::sc_logic m_cur_val; // current value of object. I hope there is any solution to my problem and thanks in advance. Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted April 22, 2016 Report Share Posted April 22, 2016 I don't see where T operator&() is overloaded in sc_signal (In SystemC 2.3.1 that I use). operator const T& () const overloads cast to T. So you can still get a reference to sc_signal. Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted April 22, 2016 Report Share Posted April 22, 2016 Your code compiles without errors. Quote Link to comment Share on other sites More sharing options...
Fabien Posted April 25, 2016 Report Share Posted April 25, 2016 Dave, I think you misinterpret the method operator const T& () const This is a cast operator that would allow to cast your signal to its underlying type. This can be called implictly, as in : sc_signal<int> sig; sig.write(2); int val = sig; # val gets the value 2 But this is not your case : your method's parameter's type is "sc_signal<T> &", so no conversion should occur here. Quote Link to comment Share on other sites More sharing options...
HSDave Posted April 28, 2016 Author Report Share Posted April 28, 2016 Fabien Yes, you are right. I have found that this was not the source which caused my problem. It was rather a problem in which 2 variables (one of type T and one of type sc_signal<T>) had the same name but the wrong one was given to the function call. This happened in a Constructor, so a simple this-> before the name of the variable solved that problem. Anyway thank you for the reply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.