1

I have to write some classes which might be usefull for programming text editor. For now I have two classes: Document and Page. I want Document to have field keeping adresses to Page objects, each for new page. First page will be created in Document constructor, next with create_page() (Document's method).

For now I have declared

Page* pages[99999];

and I write to it by

Document::pages[0] = new Page;

and it works, but I know it's quite wrong. Any ideas how should it look like?

Thanks!

Michał Werner
  • 285
  • 4
  • 10
  • 1
    This is more of a design question, and very broad. But you should definitely be using a dynamic structure as opposed to 99,999 pointers in an array. – greedybuddha May 17 '13 at 20:39

2 Answers2

3

A dynamic structure is the way to go.

Try something from the Standard Library like Vector or a List.

MarZab
  • 2,543
  • 21
  • 28
0

Many documents aren't made up of pages.

For example, this web 'page' if you print it out might cover 3 real physical paper pages. Or if I generate a pdf from some `rst markup language, it will decide how to paginate. In word you can choose a number of different views on a document, reading, reviewing, outline, I forget the others, and they all affect pagination.

Pages are really a view on a document. You can sometimes give directives in the document to have an explicit page break, but whether the view respects that is up to the view.

Your document is the model, and you can have many views including different pagination. Don't make pages part of the document.

Peter Wood
  • 23,859
  • 5
  • 60
  • 99