PDA

View Full Version : Better way to initialize QVector



lyucs
20th August 2009, 15:37
I guess my question is more about C++ then Qt, but I'm not sure.

I have a class, and it has a member that is a QVector<type>

I want to initialize it inside the Class Constructor. After some tries, I got one working:

variableName = QVector<type>::QVector<type>(0);


.h
class Protocol
{
...
typedef int second;
typedef QVector<second> conj_seconds;
...
Private:
conj_seconds list_seconds;
...
}


.cpp
Protocol::Protocol()
{
...
list_seconds = QVector<second>::QVector<second>(0);
...
}

Is there a more... efficient way? elegant way? It seems so... brute to me ;)

and,
another question,
I can't seem to be able to use "conj_seconds" as a return parameter for my methods. Any ideas why?
(yes, I included "protocol.h", and <QVector>)

thank you!

*Edit*
actually, No typedef name can be used as a return parameter, but they work fine as other parameters... :confused:

RSX
20th August 2009, 18:09
Why would you want to initialize your container? Just forget about it you don't need to do that. And your second question, put typedef's outside of the class.

lyucs
24th August 2009, 13:13
Why would you want to initialize your container? Just forget about it you don't need to do that. And your second question, put typedef's outside of the class.

I.... don't? ookay, then

It worked.

thanks!
;)

wysota
25th August 2009, 08:25
You can always do it like this:

Protocol::Protocol() : list_seconds(0) { ... }