I try to malloc an array of structs in a different struct. Is this even possible? I searched for hours and I could not find any good explaination on how to do it properly. I want an array of "book" in "library". I need the malloc, that everything is placed on the heap and not on the stack.
struct book
{
page *read_page; //page is also a struct
unsigned int id;
};
struct library
{
book *any_book = static_cast<book*> (malloc (NBR_OF_BOOKS * sizeof(book)));
for ( int book_counter = 0; book_counter < NBR_OF_BOOKS; book_counter++)
{
book[book_counter] = static_cast<book*> (malloc(sizeof(book)));
}
void* v = malloc(sizeof(book));
any_book = static_cast<book*>(v);
};
I get the following error message (line 13): no match for 'operator=' (operand types are 'book' and 'book*')