0

I have developed a tracer which basically records some metrics of the nodes. It has two files pit-tracer.hpp and pit-tracer.cpp. I was getting the above error and couldn't understand what's causing the issue.

class PitTracer : public L3Tracer {
   public:
   static TypeId GetTypeId();
 
  PitTracer();
  /**
   * @brief Constructor
   *
   * @param filename Output filename.
   */
  explicit PitTracer(const std::string& filename);

  /**
   * @brief Destructor
   */
 virtual ~PitTracer();
   
   void Trace(std::string context, Ptr<const Packet> packet, Ptr<L3Protocol> l3);

The above is the code snippet from my .hpp file and the below is from .cpp file.

    NS_OBJECT_ENSURE_REGISTERED(PitTracer);

    TypeId
    PitTracer::GetTypeId(void)
  {
    static TypeId tid =
    TypeId("ns3::ndn::PitTracer")
    .SetParent<L3Protocol>()
    .SetGroupName("Ndn")
    .AddConstructor<PitTracer>()
    //.AddConstructor<PitTracer(const std::string&)>()
    .AddConstructor<PitTracer>()
    .AddAttribute("Filename", "Output filename",
                  StringValue("pit-sizes.txt"),
                  MakeStringAccessor(&PitTracer::m_outputFilename),
                  MakeStringChecker())
    .AddAttribute("Interval", "Interval at which to write PIT sizes to output file",
                  TimeValue(Seconds(1.0)),
                  MakeTimeAccessor(&PitTracer::m_interval),
                  MakeTimeChecker());

  return tid;
}
Detailed Error message: 
In file included from ./ns3/object-base.h:23,
                 from ./ns3/object.h:29,
                 from ./ns3/object-factory.h:24,
                 from ./ns3/simulator.h:29,
                 from ./ns3/ndnSIM/model/ndn-common.hpp:24,
                 from ../src/ndnSIM/utils/tracers/pit-tracer.hpp:8,
                 from ../src/ndnSIM/utils/tracers/pit-tracer.cpp:1:
./ns3/type-id.h: In instantiation of ‘static ns3::ObjectBase* ns3::TypeId::AddConstructor()::Maker::Create() [with T = ns3::ndn::PitTracer]’:
./ns3/type-id.h:659:3:   required from ‘ns3::TypeId ns3::TypeId::AddConstructor() [with T = ns3::ndn::PitTracer]’
../src/ndnSIM/utils/tracers/pit-tracer.cpp:39:32:   required from here
./ns3/type-id.h:656:20: error: cannot convert ‘ns3::ndn::PitTracer*’ to ‘ns3::ObjectBase*’ in initialization
  656 |       ObjectBase * base = new T ();
      |                    ^~~~


  

As I have two constructors in my .hpp file I tried Adding two constructors in my .cpp file under the TypeId but it doesn't work and I even tried adding the constructor with parameters in my .cpp file it doesn't take. How can I remove this error?    

0 Answers0