template problem
From: J. Wolfram (Wolfram_09_at_gmx.de)
Date: 02/28/05
- Next message: red floyd: "Re: std::map iterator and clearing"
- Previous message: Larry Brasfield: "Re: best way to modify a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Feb 2005 20:06:33 +0100
Hi!
I need to write a template function which accepts a pointer (and a parameter
for the byte-offset between the elements and a parameter for the number of
elements.).
The different possible types which the pointer is pointing at can be for
example:
float[3]
short
byte[4]
...
So for the first type, the size of the first element would be
3*sizeof(float).
I would like to work inside the template function with a whole element, not
with each primitive data type.
The template function I created works perfectly if I use a pointer to an
element which just contains a primitive type.
If the element is array like in this example, the program crashes even
before a single instruction inside the function has been processed:
struct _AElement
{
short Element;
}*APointer;
struct _BElement
{
float Element[3];
}*BPointer;
APointer = (_AElement*)VoidPointer;
LogArray(APointer, 45, 102); // Okay!
BPointer = (_BElement*)VoidPointer;
LogArray(BPointer, 55, 400); // CRASH!
template <class ElementType> DWORD LogArray(ElementType* ArrayPointer, int
ArrayStride, int ArraySize)
{
...
}
What's the problem and what's a working alternative?
I am using the VS .Net 2004.
Thanks for your help!
- Next message: red floyd: "Re: std::map iterator and clearing"
- Previous message: Larry Brasfield: "Re: best way to modify a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]