Assignation with an array

hi,

i try to assign a value to an array type

1
2
3
4
5
6
7
  //in my .h file
  array<CompartmentTissue, MAX_TISSUE> tissue; 
   
  //in my c++ file
  for (int i = 0; i < MAX_TISSUE; i++) {
      tissue[i] = new CompartmentTissue();
  }




error i got is

no match for 'operator=' (operand types are 'std::array<CompartmentTissue, 16u>::value_type {aka CompartmentTissue}' and 'CompartmentTissue*')


any idea?
Last edited on
you would need to make tissue a pointer for that kind of syntax i believe (havent written c++ code in a while though). i think what you want is:
tissue[i](constructor_args);
on this page
http://www.cplusplus.com/reference/array/array/operator[]/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// array::operator[]
#include <iostream>
#include <array>

int main ()
{
  std::array<int,10> myarray;
  unsigned int i;

  // assign some values:
  for (i=0; i<10; i++) myarray[i]=i;

  // print content
  std::cout << "myarray contains:";
  for (i=0; i<10; i++)
    std::cout << ' ' << myarray[i];
  std::cout << '\n';

  return 0;
}


i just search a way to put CompartmentTissue object in the array... is there a way to do it?

why in my exemple that don't work?
Get rid of the new in your first post, and see if it works. the new operator returns a pointer, and you're not using pointers here. (Your example didn't use pointers, either.)

Also make sure that you have a default (as in, no-arg) constructor implemented in your CompartmentTissue class.
Last edited on
Topic archived. No new replies allowed.