468,275 Members | 1,837 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,275 developers. It's quick & easy.

Help with Non-Aggregate Type Error

1
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my pointers, but I'm not sure. Please help.

The code:
void equate(matrix *A, matrix *B)
{
int i, j;
assert(A.row_dim == B.col_dim && A.col_dim == B.col_dim);

for(i=0; i < A.row_dim; i++)
for(j=0; j < A.col_dim; j++)
A.element[i][j] = B.element[i][j];
}

A and B are supposed to be two different matrices that I will be setting equal to each other...I guess it's sorta like the classic "Swap Function" problem.

The Error:
create.h: In function `void equate(matrix*, matrix*)':
create.h:115: request for member `row_dim' in `A', which is of non-aggregate
type `matrix*'
create.h:115: request for member `col_dim' in `B', which is of non-aggregate
type `matrix*'
create.h:115: request for member `col_dim' in `A', which is of non-aggregate
type `matrix*'
create.h:115: request for member `col_dim' in `B', which is of non-aggregate
type `matrix*'
create.h:117: request for member `row_dim' in `A', which is of non-aggregate
type `matrix*'
create.h:118: request for member `col_dim' in `A', which is of non-aggregate
type `matrix*'
create.h:119: request for member `element' in `A', which is of non-aggregate
type `matrix*'
create.h:119: request for member `element' in `B', which is of non-aggregate
type `matrix*'


Thanks
Mar 6 '07 #1
2 5146
horace1
1,510 Expert 1GB
assuming matrix is something like
Expand|Select|Wrap|Line Numbers
  1. class matrix
  2. {
  3.       public:
  4.       int row_dim, col_dim;
  5.       int element[100][100];
  6. };
  7.  
and the parameters to function equate() are matrix* you use the -> operator to access data members, e.g.
Expand|Select|Wrap|Line Numbers
  1. void equate(matrix *A, matrix *B)
  2. {
  3. int i, j;
  4. assert(A->ow_dim == B->col_dim && A->col_dim == B->col_dim);
  5.  
  6. for(i=0; i < A->row_dim; i++)
  7. for(j=0; j < A->col_dim; j++)
  8. A->element[i][j] = B->element[i][j];
  9. }
  10.  
Mar 6 '07 #2
lqdeffx
39
or you can dereference them as pointers, then you would be able to use the '.' operator; but I that is a matter of preference. personally I don't mind typing an extra character each time and it lets me know at a glance that its a pointer.
Mar 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by D. Roshani | last post: by
4 posts views Thread by webdev | last post: by
2 posts views Thread by ambika | last post: by
reply views Thread by Christopher Attard | last post: by
1 post views Thread by WJScott69 | last post: by
4 posts views Thread by WebBuilder451 | last post: by
3 posts views Thread by Zach | last post: by
399 posts views Thread by =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
1 post views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.