Class inheritence
-
Guilherme? schrieb:
Why?
I think I don't need pionter because I won't use it like a vector (and there is only one, no other to point to :x ... whow problems with concepts)If you don't need a pointer, just declare it as a plain variable - so what's the problem?
so when INIDetail Details = new INIDetail it will call the constructor. yeh.. :x..... need to study :x lool
new creates an object and calls its ctor - but it creates it on the heap and gives you a pointer to its location. When you use "INIDetail Detail;" it simply creates an object on stack or inside your class and still calls its ctor.
And the good thing on this local objects is - they are fully controlled by the programm and are automatically destroyed when their function ends (objects on the heap stay alive until you destroy them explicitely by calling delete - possibly forever if you loose their adress).
-
hum ... thanks...
instead of every code ...
which part should I change? ...
actualy I took out the INIDetail * Details declaration, so as I could understand it will call the constructor anyhow and manage it automaticly, this is good because not only I don't know working with memory, I don't need it at all (explicit work) in this program, it simply will read .ini files and change it.
-
Next you should replace the Arrays inside your classes by vector<StructINIDetail> resp. vector<StructINISection> and call their methods inside the Add(), Remove() etc.
(btw, how is the desired relation between INI-Section and INI-Detail?)
-
supostly a section can have MAXDETAILS details in it.. :x
-
I'm sorry for this borring question, but are you refering to
unsigned int _IDSection[MAX_DETAILS]; unsigned int _IDDetail[MAX_DETAILS]; unsigned int _Type[MAX_DETAILS]; AnsiString _Name[MAX_DETAILS]; AnsiString _Value[MAX_DETAILS];change it to vector<StructINIDetail> ???? instead of Arrays?
-
Guilherme schrieb:
supostly a section can have MAXDETAILS details in it.. :x
In this case, there should be more then only one INIDetail object inside your INISection class (at the moment, a section has one Detail and (up to) MAXDETAIL Section-data Elements:
struct sIniDetail { ... } class INIDetail { sIniDetail data;//one Detail has only one Detail-data part ... }; struct sIniSection { ... }; class INISection { sIniSection data;//dito - one data part for the section vector<INIDetail> details;//unlimitied Detail elements public: void Add(const INIDetail& element) { details.push_back(element); } ... };(and maybe you can remove the two struct's completely and store their members direct inside the corrosponding classes)
-
Hum
... this is cool...
I didn't know vectors untill we start talking about it, I'll study how do they work and so implement it.
That way it means there is only a section for infinit details. so ... if I want to create more than a section I'll need to create that number of objects right?! but there isn't allowd to use vector that case.
so ... I was wondering this way.
I'm outter code declaire a new Section for each [SECTION] in file, but how do I access them? how can I know how much objects from a sertain class do I have?
-
Guilherme schrieb:
Hum
... this is cool...
I didn't know vectors untill we start talking about it, I'll study how do they work and so implement it.
That way it means there is only a section for infinit details. so ... if I want to create more than a section I'll need to create that number of objects right?! but there isn't allowd to use vector that case.
so ... I was wondering this way.
I'm outter code declaire a new Section for each [SECTION] in file, but how do I access them? how can I know how much objects from a sertain class do I have?One INISection object represents one section from your INI file - if you need more than one, you could still use a vector<INISection> somewhere in your programm (or a class 'INIFile' which encapsulates all sections like the INISection encapsulates all details).
btw, maybe you could use a map<> to have a direct corrospondence between a section's name and its contained data (and between a detail's name and its value).
-
hum... I though vector<> didn't allowd to access classes only DataTypes
... if a class a DataType?!
loolwell
map<> so will be a nice idea refering to what you said 
thank you a lot.
By the way, do you know a nice book whitch go through these subjects?
thank you once more
-
if you want to learn about the C++ Library, you could use this one:
The C++ Standard Library | ISBN: 0201379260
(for general concepts (syntax, class design etc) you should search the web for some tutorials and books - maybe you also could follow the link "Bücher" here (on top of the page), even if most of the books are written in German)edit: C++ containers allow any kind of data inside them, as long as they follow some preconditions (copieable and sometimes comparable) - even your classes.
-
One more, thank you a lot.
I think I'll borrow you many more times
...