 |
|
 |
Yes,
This code is a total waste of time, dude has all kinds of incorrect information. He refers to using STL clases when every class he is using CTree, CTreeItem are not in any sence STL they are the MFC common classes for the windows common control CTreeCtrl ect, ect. vector would be the STL container. Now lets look at why this code is garbage.
1) Doesnt provide a working project using this.
2) As others said no code to traverse the vectors and accually do something with them.
3) Doesnt even provide the constructor's, destructor's and accually this wont even compile on a good compiler.
4) Using a Static approch for what fields are created as containers and no base class to even see this in a tree control at least thats what I assume when I see MFC class names as he is using.
5) Every class should have the constructor's and destructor's even if you dont call any functions or take any action, its just good code practice and alot of compilers will complain leaving them out. Also in his CTree class he forgot to declare Public: so of course thats why it wont compile, and he provides no entry point to his Location Class.
I agree with the others people who post incomplete code in an attempt to teach someone or even get some internet fame should keep their crap to themselves as I run into this kind of code everywhere while doing normal lookups on general information and it is just a waste of time. I dont agree that this would even be good for a NOOB cause a NOOB would not even be able to test it.
The next worse thing is someone posts code with errors and then I run accross the same code with same errors on other sites with several people claiming they wrote it, when its clear its just copy and paster want to be coders. How Freaking Lame....
|
|
|
|
 |
|
 |
Hello,
I am pretty new in object oriented programming and having trouble with tree data structure.
I am trying to add new children to children.I mean trying to advance my tree.
What is the problem with this usage and what is its solution?
char *temp;
CTreeCountry,Washington,WhiteHouse;
Country.item.name="USA";
Washington.item.name="Washington";
WhiteHouse.item.name="White House";
Country.children.push_back(&Washington);
Washington.children.push_back(&WhiteHouse);//Adding new children to a children
temp=new char(WhiteHouse.item.name.size());
//strcpy(temp,Washington->children[0]->item->name.c_str());//PROBLEM
//strcpy(temp,Washington.children[0].item.name.c_str()); //PROBLEM
Any help would be appreciated...
And the other thing is how can I find the parent of a children?
Thank you for your interest
|
|
|
|
 |
|
 |
I understood this part
//strcpy(temp,Washington->children[0]->item->name.c_str());//PROBLEM
//strcpy(temp,Washington.children[0].item.name.c_str()); //PROBLEM
the correct one should be;
strcpy(temp,Washington.children[0]->item.name.c_str());//since children take pointers
But if you give me some example about how to traverse this tree any additional method to this simple tree class, how to find the parent of a node etc., it would be appreciated...
|
|
|
|
 |
|
 |
C as a class-prefix is bad style, public-members as well.
|
|
|
|
 |
|
 |
where did you saw C as a class prefix is bad style ?
|
|
|
|
 |
|
 |
I am a newbie and IMHO it is very useful...
|
|
|
|
 |
|
 |
i found it very useful, and i thank you for posting it.
|
|
|
|
 |
|
 |
being a noob concerning to STL i'ts very useful to understand it.
|
|
|
|
 |
|
 |
This article could be of value if you were to offer more information about your idea (e.g. why is your idea a better choice for doing something than what already exist). Then follow that with an explanation (and sample code) to support your reason for believing that to be the case. When the person reading your article has finished doing so, he/she should have no doubt that what you have just offered, is indeed superior to what already exist, or widely known.
To find out how you'd go about determining when something is "widely known" might require a little research on your side, which in the end might even convince you that more work has to be done on the article you propose submitting.
I gave you a '3' for it being your first article. Shoot for a '5' with your next one.
William
Fortes in fide et opere!
|
|
|
|
 |
|
 |
Thank you for your reply. My idea was to show the easiest and fastest way to create a tree structure using STL vector template.
Sometimes it is not very clear how to create a tree structure using STL (as far as I know there is no simple STL tree template).
I wanted to share my idea how to do this.
|
|
|
|
 |
|
 |
Your wanting to share your idea about something with the community, or how to do something, is noble. That is what CodeProject is all about, but there is a standard of excellence which you as an individual must also demonstrate (which is why a lot of members BEFORE submitting an article to CodeProject, will first check things out right here on CodeProject, to see if something similar already exist or to see what other writers may have done on the subject).
Nobody expects you to write about, or submit an idea on the next "Killer App", which (who knows) you may very well do. But the point is, by researching right here on CodeProject, you could come away with a pretty good idea on what it takes to write a good article.
Granted, the STL doesn't (at this time) have an algorithm for creating tree structures, but that doesn't mean you should submit an article on the subject if it's not going to be really good! After all, for something that doesn't exist right now, and for which you are going to introduce the first of its kind, that alone should tell you that it better be good.
Just chuck this one up to experience and shoot for a '5' with your next article. You have the "right stuff"; it just needs a little polishing up. Here's to your success!
William
Fortes in fide et opere!
|
|
|
|
 |
|
 |
You understood me really good. I have some code and solutions to share with cominity and I had to start with something.
May be this article was really worthless, who knows... I remembered myself trying to create a simple tree, searching the web for comments and solutions... Maybe I could help someone... Who knows...
Thank you very much for your politeness and understanding.
|
|
|
|
 |
|
 |
Sometimes just bringing attention to a topic is pretty good. It would also be good for naysayers to improve the article instead of just saying it falls short. It's always easier to complain than actually do something.
Anyway, a typical thing is that a tree needs to hold different types of items at various levels, but all those types (except maybe the ones used for node items) need to inherit from the tree-type so that they can have children.
|
|
|
|
 |
|
 |
Oops... instead of 'node' in the parent post, I should have said 'leaf'.
|
|
|
|
 |
|
 |
I'm sorry to say this, but this article is worthless. We already know how to define a class. It is ridiculous to say "this class can be extended". Not only is that statement obvious, but it should be you who extends the class and you who includes decent functionality. Your code, such as it is, completely ingores all the issues involved with parent-child trees.
I have no idea how anyone could justify posting useless articles like this - it neither presents usable code or a tutorial.
Another article that deserves lower than 1 out of 5
|
|
|
|
 |
|
 |
I agree, it's wothless... A better choise is to use heavy tree structures to implement simple things...
|
|
|
|
 |
|
 |
Pavel Molchanov wrote:
heavy tree structures
What are you talking about? Clearly you cannot defend this rubbish. It seems that not only are you inexperienced, you are also arrogant.
|
|
|
|
 |
|
 |
but we can impove on the time effiiency of the code..but dont u feel we need to make user friendly easy comprehendable codes....
|
|
|
|
 |
|
 |
I agree - this was a complete waste of time to read, and totally worthless. I wish code project would filter out this sort of stuff.
|
|
|
|
 |
|
 |
Not good code, but useful to newbie
|
|
|
|
 |