[ndnSIM] C++ Reference for NDN

John Baugh jpbaugh at umich.edu
Thu Jun 14 02:41:24 PDT 2018


George,

I'm not sure of your background, so I'm not entirely sure where to start,
but I'll assume you have fundamental CS training in things like data
structures and ADTs, algorithms, etc.

So here's my explanation and links about the concepts you described:


   - *shared_ptr*
      - If you're familiar with so-called "raw pointers" in C++ (those
      using *, such as in MyClass* something = new MyClass();) then
you know some
      of their limitations
      - One major limitation of raw (regular) pointers is that you have to
      remember to delete them
      - Many other languages have so-called automatic garbage collection or
      something similar where you don't have to manage your own memory (e.g.,
      Java, C#, etc.)
      - shared_ptr is a full-fledged class that allows you to point to
      objects and primitives, but it maintains a reference could and you don't
      have to remember to delete them later
      - Decent references:
         - http://en.cppreference.com/w/cpp/memory/shared_ptr
         - http://thispointer.com/learning-shared_ptr-part-1-usage-details/
         - *iterator*
      - In general, the iterator ADT can be seen as a specialized object
      whose sole purpose is to help you move through (traverse) a collection
      (data structure), such as a list, multiset, etc.
      - Because an *index* is seen as a simple way to move through an
      array, an iterator is a bit like an analogous yet more
object-oriented way
      of doing so
      - The term "index" wouldn't really be appropriate for say, a linked
      chain of nodes (e.g., in a linked list, linked bag/multiset,
dictionary) so
      an iterator is used to traverse such a container, and is in fact, more
      general than an index, since an index is array-oriented
      - References:
         - https://www.cprogramming.com/tutorial/stl/iterators.html
         - https://en.cppreference.com/w/cpp/concept/Iterator
         - *const*
      - This keyword is used in many different scenarios, so I'm not sure
      what your context is
      - const, when used in front of a declaration indicates that the
      "variable" is actually a constant and cannot be changed (e.g., const int
      someVar = 150;)
      - const, when used after the name of a member function (method)
      inside a class means that *that method* cannot change the internal
      data of the object (e.g., void someFunction() const;)
      - const, when used with raw pointers has many different meanings
         - const int* myPtr   // pointer to an integer whose value is
         constant (you can change the pointer to point to something
else, but can't
         change the value of the int it points to.)
         - int* const myPtr  //a constant pointer to an integer (you cannot
         change what the pointer points to, but you can change the value at the
         memory address to which it points)
         - const int* const myPtr  //you can neither change what it points
         to (i.e., the address) nor the value to which it points
      - *auto*
      - This isn't really a data type per se.  It's called a *specifier*
      - Although C++ is a *strong-typed *or *strict-typed* language
      (meaning a variable is declared with a type and can only hold that type),
      auto can be used to deduce the type from the initializer
         - auto myVar = 15;  //compiler will deduce that this is an integer
         - auto yourVar = 3.14159;  //compiler will deduce this is a float
      - However, you don't usually use it with simple types like that -
      it's frequently used with more complex types, those using templates, etc.
      - It's used in some other contexts, but I think the above is probably
      the most common usage
      - See https://en.cppreference.com/w/cpp/language/auto



Hope this helps! :)

Dr. John P. Baugh
University of Michigan - Dearborn

On Thu, Jun 14, 2018 at 5:17 AM, george assaf <engdotgeorge at gmail.com>
wrote:

> Hi All,
> I need a good reference for C++ programming and in particular contains
> information about the advanced following concepts: *shared_ptr*,
> *iterator *, *const *descriptor , *auto *type ...
> I would be grateful to you..
> thank you
>
>
> _______________________________________________
> ndnSIM mailing list
> ndnSIM at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20180614/e946d30a/attachment.html>


More information about the ndnSIM mailing list