By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

Help with Non-Aggregate Type Error

P: 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
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
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

P: 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.