Karel-Lodewijk's Profile
Reputation: 445
Architect
- Group:
- Mentors
- Active Posts:
- 853 (1.07 per day)
- Joined:
- 17-March 11
- Profile Views:
- 4,069
- Last Active:
Apr 27 2012 04:22 PM- Currently:
- Offline
Previous Fields
- Country:
- BE
- OS Preference:
- Linux
- Favorite Browser:
- FireFox
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 275
- Expert In:
- C/C++, Ruby
Posts I've Made
-
In Topic: Searching a BST error
Posted 22 Apr 2012
strcpy(str[1],tree->b_word); will fail when tree is an invalid pointer or NULL pointer, so I would look in that direction,
Do you ever call it on an a NULL node directly ?
Do you initialize left and rigth to NULL when they are not set ?
I also notice you don't return the results of your recursive calls.
Basically when dealing with recursion you probablky want to to check your stop condition first, in more or less pseudocode:
node__t *search_bst(node__t *tree,char targetword[50]) { if (tree == NULL) return NULL; //not found if equal return tree; else if smaller return search_bst(tree->left, targetword); else //larger return search_bst(tree->rigth, targetword); }
But also in this code left and rigth must be explicitly set to NULL on creation when there is no left or rigth child, C/C++ will not do this automatically. -
In Topic: Manageability improvments
Posted 22 Apr 2012
Well you can see that the 3 connection classes look very similar.
In my opinion it would be much better to seperate a connections from what it connects to and what is sends. So 1 connection class with a function connect that takes a parameter(s) that tells it what to connect to. And a send function that takes as a parameter what it should send. -
In Topic: syntax error
Posted 22 Apr 2012
for(current=tree;current!=NULL) should be for(current=tree;current!=NULL;). A for loop header cotnains 3 statements, they can be empty, but you do need to keep the ;. -
In Topic: Using functions trouble
Posted 21 Apr 2012
Well basically they are asking you to write two functions that could look something like this.
string get_guess(string& letters_used) { //asks the player for a correct guess and return it //also update letters_used } bool check_guess(string word, string guess) { //Print relevant output, returns true if the guess is correct, otherwise false }
The code that should go into these functions is basically all there. It's a restructuring excercise.
The second step would then be to write the main loop using these 2 functions. -
In Topic: For any class object number of constructor = no of destructor ?
Posted 24 Mar 2012
Hezekiah, on 24 March 2012 - 02:38 PM, said:++(++i); //will fail
Yes, that code will fail with your Counter class, but if i was declared as one of the built-in types (e.g. int), it should work (I think). It is usually a good idea to model your overloaded operators as close as possible to the built-in operators. Changing the return type of Counter::operator++ to Counter& (without the const), will allow the code above to work with both your Counter class and the built-in types.
I agree.
Yes ++(++i); will fail if i is of type Counter with this operator:
const Counter& Counter::operator++() { ++itsValue; return *this; }
It will fail because (++i) will return a const Counter& and calling ++ on it is illegal because it is a const reference.
And indeed, if i was an int (or any built-in type) it would work because the built-in ++ operator for integers will return something that is modifyable or in other words a reference, not a const reference.
And yes it is a good idea to model your user defined operators after the behavior of the built-in operators, this is the bahavior people expect.
So despite what you book said, it would be better to implement your ++ operator like this:
Counter& Counter::operator++() { ++itsValue; return *this; }
My Information
- Member Title:
- D.I.C Addict
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Full Name:
- Karel-Lodewijk Verdonck
Contact Information
- E-mail:
- Click here to e-mail me
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
raspinudo
31 May 2012 - 11:41general07z
18 Feb 2012 - 22:21Best Regards and respect
Karel-Lodewijk
05 Feb 2012 - 09:52Cyclopses
31 Jan 2012 - 05:05ishkabible
12 Oct 2011 - 18:38