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. [solved] need my class with a <type> extension
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.3k Views 1 Watching
  • 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 Offline
    N Offline
    Nobody-86
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • N Offline
        N Offline
        Nobody-86
        wrote on last edited by
        #3

        Hi,

        thank you very much.

        -> Solved

        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