Qt World Summit: Register Today!

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

  • 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).


  • Lifetime Qt Champion


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

  • Hi,

    thank you very much.

    -> Solved

Log in to reply