Hi,
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
which creates a vector, that constructs with size=64;
Is there a std:: way to sdo this, or must I make a template class
like:
template class<type T, int fixsizemyvec:public std::vector<T>
{
myvec() : std::vector<T>(fixsize) {}
};
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do www.GLBasic.com 9 5096
Gernot Frisch wrote:
Hi,
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
Use the same technique you do below and initialize during construction.
>
which creates a vector, that constructs with size=64;
Is there a std:: way to sdo this, or must I make a template class
like:
template class<type T, int fixsizemyvec:public std::vector<T>
{
myvec() : std::vector<T>(fixsize) {}
};
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do www.GLBasic.com
Gernot Frisch wrote:
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
which creates a vector, that constructs with size=64;
Declaration of a member doesn't construct anything. If you want to
initialise your member with a certain expression, use the constructor
initialiser list.
Is there a std:: way to sdo this, [..]
Yes, it's called "member initialiser list". Look it up.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Gernot Frisch" <Me@Privacy.neta écrit dans le message de news: 4j************@individual.net...
>
Hi,
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
which creates a vector, that constructs with size=64;
Is there a std:: way to sdo this, or must I make a template class like:
struct foo
{
std::vector<intm_i;
foo() : m_i(64) {} // construction with m_i initialized
};
One of the vector constructor takes a size_type as parameter.
it uses that to resize the vector at construction. After construction
your vector has 64 int allocated (in this case).
the following will also allocate 64 int in your vector but without using the
ctor initializer list
struct foo
{
std::vector<intm_i;
foo()
{
m_i.resize(64);
}
};
Here m_i is first constructed by the way of vector's default constructor.
Even if you dont type it, the foo constructor looks like this
[...]
foo() :
m_i() // this calls the constructor taking no arguments
{
m_i.resize(64);
}
[...]
So aftyer construction, the vector has a size of 0.
After that it is resized with his resize member function.
Eric
>I want to be able to write:
>>
class foo { std::vector<intm_i (64); }
Use the same technique you do below and initialize during
construction.
>> which creates a vector, that constructs with size=64;
Is there a std:: way to do this, or must I make a template class like:
template class<type T, int fixsizemyvec:public std::vector<T> { myvec() : std::vector<T>(fixsize) {} };
This should be in the std next version. I think it's a very convenient
way of transforming old code:
struct foo
{
int bar[MAX_SIZE];
};
into
struct foo
{
fix_vec<int, MAX_SIZEbar;
};
On 2006-08-09 12:15:02 -0400, "Gernot Frisch" <Me@Privacy.netsaid:
>
Hi,
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
which creates a vector, that constructs with size=64;
Is there a std:: way to sdo this, or must I make a template class like:
template class<type T, int fixsizemyvec:public std::vector<T>
{
myvec() : std::vector<T>(fixsize) {}
};
How about :
class foo
{
std::vector<intm_i;
public:
foo() : m_i(64) {}
};
--
Clark S. Cox, III cl*******@gmail.com
Gernot Frisch wrote:
This should be in the std next version. I think it's a very convenient
way of transforming old code:
struct foo
{
int bar[MAX_SIZE];
};
into
struct foo
{
fix_vec<int, MAX_SIZEbar;
};
It already is. Check out std::tr1::array (aka boost::array).
Cheers! --M
On 2006-08-10 03:53:10 -0400, "Gernot Frisch" <Me@Privacy.netsaid:
>>I want to be able to write:
class foo { std::vector<intm_i (64); }
Use the same technique you do below and initialize during construction.
>>> which creates a vector, that constructs with size=64;
Is there a std:: way to do this, or must I make a template class like:
template class<type T, int fixsizemyvec:public std::vector<T> { myvec() : std::vector<T>(fixsize) {} };
This should be in the std next version. I think it's a very convenient
way of transforming old code:
struct foo
{
int bar[MAX_SIZE];
};
into
struct foo
{
fix_vec<int, MAX_SIZEbar;
};
Take a look at boost::array.
<http://www.boost.org/doc/html/array.html>
--
Clark S. Cox, III cl*******@gmail.com
How about:
class foo
{
std::vector<intm_i;
public:
foo() : m_i(64) {}
};
the c'tor is in a different file. I had 20 classes all implemented in
on cpp, but different header - no very clever... It worked my way.
Thank you.
Gernot Frisch wrote:
I want to be able to write:
class foo
{
std::vector<intm_i (64);
}
Use the same technique you do below and initialize during
construction.
>
which creates a vector, that constructs with size=64;
Is there a std:: way to do this, or must I make a template class
like:
template class<type T, int fixsizemyvec:public std::vector<T>
{
myvec() : std::vector<T>(fixsize) {}
};
This should be in the std next version. I think it's a very convenient
way of transforming old code:
struct foo
{
int bar[MAX_SIZE];
};
into
struct foo
{
fix_vec<int, MAX_SIZEbar;
};
This is not the same code. Using fix_vec, your vector would still be
resizeable.
/Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve |
last post by:
Hi,
I'm using a std::vector to store a list of user defined objects. The vector
may have well over 1000 elements, and I'm suffering a performance hit. If I
use push_back I get a much worse...
|
by: Honestmath |
last post by:
Hi,
I added the following line to my code within a class declaration:
std::vector<Date> m_duedates(100);
I also tried:
std::vector<Date> m_duedates(100, Date());
|
by: Anonymous |
last post by:
Is there a non-brute force method of doing this?
transform() looked likely but had no predefined function object.
std::vector<double> src;
std::vector<int> dest;
...
|
by: simon |
last post by:
Hi,
First some background.
I have a structure,
struct sFileData
{
char*sSomeString1;
char*sSomeString2;
|
by: John |
last post by:
I have a function declaration that gives an error while compiling.
Can anyone help me figure this one out?
inline void create(const std::vector< myclass >& plist,
std::vector< myclass...
|
by: Ross A. Finlayson |
last post by:
I'm trying to write some C code, but I want to use C++'s std::vector.
Indeed, if the code is compiled as C++, I want the container to
actually be std::vector, in this case of a collection of value...
|
by: Dilip |
last post by:
If you reserve a certain amount of memory for a std::vector, what
happens when a reallocation is necessary because I overshot the limit?
I mean, say I reserve for 500 elements, the insertion of...
|
by: mathieu |
last post by:
Hello,
I am looking at the API of std::vector but I cannot find a way to
specify explicitely the size of my std::vector. I would like to avoid
vector::resize since it first initializes the...
|
by: jacek.dziedzic |
last post by:
Hi!
I need to be able to track memory usage in a medium-sized
application I'm developing. The only significant (memory-wise) non-
local objects are of two types -- std::vector<and of a custom...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |