Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Proplems understanding C++ templates.

Proplems understanding C++ templates.

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jeroi
    wrote on last edited by
    #1

    I have problems understanding C++ templates. I have read that templates are for unknown types and c++ have more features than C# and since I am doing converting code I have troubles to understand whats wrong here is:

    @template<typename T>
    class IDable : public IIDable
    {
    public:
    T Data;

    IDable(const QString &id, T t)
    {
    this->id = id;
    this->Data = t;
    }

    private:
    QString id;
    const QString &getID() = IIDable->ID->get const
    {
    return id;
    }

    };

    //C# TO C++ CONVERTER TODO TASK: There is no native C++ template equivalent to generic constraints:
    template<typename TType> where TType : IIDable@

    The error message from converter sofware tells something but it is not clear issue for me as I have never used templates. How to modify this code to C++ eqvalient?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      This is hardly a Qt issue.

      From a C++ template view neither line 15 nor line 23 make sense.

      @
      template<typename T>
      class IDable : public IIDable
      {
      public:
      T Data;

      IDable(const QString &id, T t)
      {
      this->id = id;
      this->Data = t;
      }

      private:
      QString id;

      const QString &getID() const
      {
          return id;
      }
      

      };

      //C# TO C++ CONVERTER TODO TASK: There is no native C++ template equivalent to generic constraints:
      // template<typename TType> where TType : IIDable
      @

      So you should be able to compile, but most likely some functionality is missing.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jeroi
        wrote on last edited by
        #3

        Is this quick and dirty fix for this:

        @template<typename TType> class GenericRegisterer { private: GenericRegisterer(){}};
        template<> class GenericRegisterer<IIDable> { public: GenericRegisterer(){}};@

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jeroi
          wrote on last edited by
          #4

          It is not because TType is not defined for next class so GenerigRegister don't know variable TType.

          1 Reply Last reply
          0
          • JohanSoloJ Offline
            JohanSoloJ Offline
            JohanSolo
            wrote on last edited by JohanSolo
            #5

            //C# TO C++ CONVERTER TODO TASK: There is no native C++ template equivalent to generic constraints:
            template<typename TType> where TType : IIDable

            What is that line supposed to achieve?

            It is not because TType is not defined for next class so GenerigRegister don't know variable TType.

            Definitely not. The template< typename XX > syntax is used to tell the compiler to "build" a method / class as soon as you are using the method / class with a defined type (int, custom class, etc.). The keyword placed after typename will just be replaced by the used type at compile time and does not mean anything.

            `They did not know it was impossible, so they did it.'
            -- Mark Twain

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved