|
-
September 4th, 2009, 09:56 PM
#1
Overloading a matrix constructor for 1 and 2 dimensional arrays.
Hiya, I want to be able to construct my class from either a 1D or 2D array but I don't know how to overload the constructors according to how many dimensions the array has.
I get the feeling that it might not be possible exactly, but I hope someone knows a way to achieve the same or a similar effect. I couldn't find anything specific about this on the web or in the books I have.
Here's a roughish example of what I'm trying to do:
eg
class matrix4
{
public:
matrix4( float * 1DArray );
matrix4( float * 2DArray );
private:
float elements[4][4];
}
matrix4::matrix4( 1DArray )
{
for( int i = 0; i < 4; i++)
{
for( int j = 0; j < 4; j++)
{
elements[i][j] = 1DArray[ i*4 + j ];
}
}
}
matrix4::matrix4( 2DArray )
{
for( int i = 0; i < 4; i++)
{
for( int j = 0; j < 4; j++)
{
elements[i][j] = 2DArray[ i ][ j ];
}
}
}
Hope you can help. I'm fairly new to all this. Thanks for looking!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|