N
newbix
Hi!
I have a class with a method that uses a container (vector). To avoid
frequent initialization of this container each time the method is
called I've declared this container as a class attribute.
Alternatively I could have declared this container as a static object
inside the method. What do you think, which solution is better:
attribute or static object?
Thank you in advance!
Example:
// attribute:
class A
{
std::vector v;
void do_something ()
{
// use v here
};
};
// static object:
class A
{
void do_something ()
{
static std::vector v;
// use v here
};
};
I have a class with a method that uses a container (vector). To avoid
frequent initialization of this container each time the method is
called I've declared this container as a class attribute.
Alternatively I could have declared this container as a static object
inside the method. What do you think, which solution is better:
attribute or static object?
Thank you in advance!
Example:
// attribute:
class A
{
std::vector v;
void do_something ()
{
// use v here
};
};
// static object:
class A
{
void do_something ()
{
static std::vector v;
// use v here
};
};