katang Posted June 4, 2017 Report Posted June 4, 2017 I want to define a FIFO of user-defined structures. The program below presents with message: no match for 'operator <<' If I change <Transfer> to <int>, int compiles fine. #ifndef scMWE_h #define scMWE_h #include <systemc> #include <iostream> typedef struct { int Select; int Content; } Transfer, *TransferPtr; SC_MODULE(scMWE) { scMWE(sc_core::sc_module_name nm); sc_core::sc_fifo<Transfer> from; }; #endif #include "scMWE.h" SC_HAS_PROCESS(scMWE); scMWE::scMWE(sc_core::sc_module_name nm) : sc_core::sc_module(nm) {} Quote
maehne Posted June 4, 2017 Report Posted June 4, 2017 The type you pass as a template argument to sc_core::sc_fifo<T> has to fulfill a couple of rules, which are described in detail in clause 6.23.3 of the IEEE Std 1666-2011. In summary, your type Transfer needs to provide: a) The output stream operator: std::ostream& operator<<(std::ostream&, const Transfer&); This one is missing, which is hinted to you by the compiler error. b) The assignment operator (not missing as auto-generated by the compiler for a struct): const Transfer& operator=(const Transfer&); c) The default constructor if any other constructor is defined for your type Transfer (not necessary for a pure struct as in your code snippet): Transfer::Transfer(); Quote
katang Posted June 4, 2017 Author Report Posted June 4, 2017 Thank you, I really missed the point Quote
katang Posted June 4, 2017 Author Report Posted June 4, 2017 In my enhanced version, the compiler said the operator must take exactly one argument. I really cannot find out why. #ifndef scMWE_h #define scMWE_h #include <systemc> #include <iostream> struct Transfer_Type { int Select; int Content; std::ostream& operator << (std::ostream& os, const Transfer_Type& I) { return os; } }; SC_MODULE(scMWE) { scMWE(sc_core::sc_module_name nm); sc_core::sc_fifo<Transfer_Type> from; }; #endif Quote
AmeyaVS Posted June 5, 2017 Report Posted June 5, 2017 Hello @katang, You need to declare the method as a friend method and the definition has to be moved to corresponding source file. For e.g.: // scMWE.h #ifndef scMWE_h #define scMWE_h #include <systemc> #include <iostream> struct Transfer_Type { int Select; int Content; friend std::ostream& operator << (std::ostream& os, const Transfer_Type& I); //< Declaration for the friend method. }; SC_MODULE(scMWE) { scMWE(sc_core::sc_module_name nm); sc_core::sc_fifo<Transfer_Type> from; }; #endif scMwe.cpp: // scMWE.cpp #include "scMWE.h" // Definition for the friend method. std::ostream& operator << (std::ostream& os, const Transfer_Type& I) { return os; } Hope it helps. Regards, Ameya Vikram Singh Quote
apfitch Posted June 6, 2017 Report Posted June 6, 2017 There's a complete example here: https://www.doulos.com/knowhow/systemc/faq/#q1 regards Alan P.S. Note it uses inline friends, which is perhaps a bit quirky. Quote
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.