A C++ syntax that I don't know.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pdsilva
    New Member
    • Dec 2011
    • 2

    #1

    A C++ syntax that I don't know.

    Hi guys

    I am new here.

    Recently I began to work with c++, and I found a line in the code,that I don't know what it means.
    Please give me an explanation about it.

    Here it is:
    std::material<s td::string, Classe1 *> mClasse1;

    To me material is a methode of std.
    mClasse1 is an object being declared,but what this means "<std::stri ng, Classe1 *>"I have never saw this kind of statement. What means operator "<" and ">".

    Thank you in advance

    Paulo
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Code:
    std::material<std::string, Classe1 *> mClasse1;
    This says that mClass1 is an object created from a template in the std namespace that was given std::string and a Class1* as parameters.

    Like this:

    Code:
    template <class T>
    class MyClass
    {
    public:
       T data;
    };
    Then in your program:

    Code:
    MyClass<int> myObject;
    I'm not advocating public data but only explaining the syntax.

    Comment

    • pdsilva
      New Member
      • Dec 2011
      • 2

      #3
      Thanks, you helped me a lot, now it clears to me, what the code here are doing.

      Paulo

      Comment

      Working...