CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    4

    can't understand this piece of code

    Dear All,

    I am seeking the help of people who know c++ .

    Could anybody explain to me what is going on here ?

    ( i am tryin to learn ns3 and these codes are taken from ns3 tutorial chap7 )

    class MyObject : public Object
    {
    public:
    static TypeId GetTypeId (void)
    {
    static TypeId tid = TypeId ("MyObject")
    .SetParent (Object::GetTypeId ())
    .AddConstructor<MyObject> ()
    .AddTraceSource ("MyInteger",
    "An integer value to trace.",
    MakeTraceSourceAccessor (&MyObject::m_myInt))
    ;
    return tid;
    }
    MyObject () {}
    TracedValue<int32_t> m_myInt;
    };


    void
    IntTrace (int32_t oldValue, int32_t newValue)
    {
    std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
    }


    int
    main (int argc, char *argv[])
    {
    Ptr<MyObject> myObject = CreateObject<MyObject> ();
    myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback(&IntTrace));
    myObject->m_myInt = 1234;
    }

    your help is HIGHLY appreciated

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: can't understand this piece of code

    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  3. #3
    Join Date
    Jan 2012
    Posts
    4

    Smile Re: can't understand this piece of code

    Merci beaucoups !! that was extremely useful !

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured