Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] need my class with a <type> extension

    C++ Gurus
    2
    3
    1154
    Loading More Posts
    • 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.
    • N
      Nobody-86 last edited by

      Hi,

      I like to create a class which is (amongst others) able to store a single number, to represent a datapoint. Now, becouse the some data could be more important than other, I like to give the (end-)user a choice if my class should store the data as int, float or double.

      Unfortunately I have no idea how to do that. And (even more bad) I have no Idea how to name my problem to google it.

      Becouse I have no Idea of the name for my problem, here a Example:
      @
      QList<int> myIntList; // store data as integer
      QList<float> myFloatList; // store data as float
      QList<double> myDoubleList; // store data as double
      @

      I need something similar:
      @
      Datapoint<int> myIntData; // store data as integer
      Datapoint<float> myFloatData; // store data as float
      Datapoint<double> myDoubleData; // store data as double
      @

      First question: What is the name of these <TYPE>? I guess I need some basics here.

      Secound question: How can I create a class whis has these <TYPE>? (may be anserd automaticaly if I read the basics from question 1).

      Thanks,

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You are looking for "templates":http://www.cplusplus.com/doc/tutorial/templates/

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • N
          Nobody-86 last edited by

          Hi,

          thank you very much.

          -> Solved

          1 Reply Last reply Reply Quote 0
          • First post
            Last post