Click here to Skip to main content
15,745,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi folks,

I'm trying to write a simple (console/text based) spreadsheet program. I'm a relative novice.

I have written programs before where the 2D 'box' was of one data type only (int, float, char etc). Now I need the spreadsheet to be able to store different data types in the cells.

I have a little knowledge of templates but I cannot figure out how to link my 2D vector to said input values of the cells (if that makes any sense).

I'd appreciate any help.

What I have tried:

I have tried using smart pointers but I don't really know much about them and failed miserably.
Updated 8-Apr-16 5:10am
Sergey Alexandrovich Kryukov 8-Apr-16 14:40pm    
"Failed" is not informative; sure, certainly learn smart pointers. But master them well before getting to such a big application, on some minimalistic prototypes, not even prototypes of such applications.

Generally, your question is almost about nothing. The problem is not reduced to pointers or some other narrow aspects. The application is quite feasible for an individual behavior, but it has a lot more aspects. From your words where you self-qualified yourself, I would strongly recommend to sharpen your skills on simpler projects.


1 solution

Your array should probaly be an array of pointers. Each pointer will then need to point to a class object or structure that implements the object referred to by the cell. Each object can then implement the methods necessary to store, manipulate and display its contents.
Share this answer
SpicaX 8-Apr-16 11:43am    
Richard MacCutchan: Thanks for the reply.

What kind of pointers should these be? I'm not positive I know how to do that.


While this post was up I was thinking I could alternatively make a linked list for this purpose. What do you think?
Richard MacCutchan 8-Apr-16 12:24pm    
Er, the type I described in my answer. As to a linked list, I don't see how that would fit with a spreadsheet type of structure.
Sergey Alexandrovich Kryukov 8-Apr-16 14:36pm    
Forget about linked list. The structure is very different. For practical purpose, it could be the "linked graph", but then the word "linked" would be redundant :-) The graph needs linking between cells up and down, left and right. But the array of cell pointers would be better (time performance of the access of O(1)). For flexibility, it could rather be a vector of vectors of cell pointers.

The UI can be built on some kind of general-purpose grid view.

SpicaX 9-Apr-16 16:04pm    
That is indeed what I meant by linked list. I'm a bit stuck on the vector of vectors of cell pointers currently!

Thanks for the reply.
Sergey Alexandrovich Kryukov 9-Apr-16 22:10pm    
Where did you stuck? What's the problem?
I mean, let's say, you have number of cell and pointers to them.
The vector of such pointer can represent a row.
Several rows then will be the vector of such vectors.

Likewise, you can represent column as a vector of pointers to cells.
And vector of such vector is the same sheet, from a different point of view.

What could be a problem here?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900