| Doth (14) | |||||||||||
|
I started doing a program that is supposed to solve crosswords ( search for words in all directions ). So basicaly I have a field [X:Y] , there is a letter on every location ( '0' for empty ) and I have to keep track if that letter was used in a word or is left and that's why I made that a struct outside the class and I use it as a variable in the main class. I also add new words that I'm searching for. I made a struct for that too because I have to keep track if the word was found or not and it also has to contain the word itself.
It looks like this , csField is the class , the whole field. csItem is the smallest part of the field, it has coordinates [x:y]. csSearch is the struct that contains the words that I'm looking for. I add new words with the method pushWord :
words is a integer variable inside the class csField that keeps track of how many words are there. The algoritm that is searching for the words is not wrong, actually I was suprised that it is working... The problem is something i've never met before and I don't understand what is happening , it's working just partially and I tried to solve it but without success. If I show the whole field that is read from a text file it is working without any problem, the item[][] contains the right letters and the state variable is initialized to false. The same applies for search[], I add all the words and the string inside the struct contains all of them without problem. But when I need to change the value of any boolean of the struct, be it search, indicating that the word was found or be it item, indicating that the letter was used in a word, it won't change the value to true. Here is the code in which I change the value of search : (It is inside a method of the class csField)
And here is the part where I change the item value :
Both of the variables should change it's value from FALSE to TRUE but when I put them to the output they are still false. But if I have an object of the class, let's say csField Alpha(30); if I change the value in main() like, Alpha.setItemState(0,0,true); It will change the variable, but if I do it in the class using this-> it won't change anything. I was using the debugger to make sure it goes to the line where it is supposed to change it and it goes to the line, no error, but the value is left unchanged. Why is this so ? | |||||||||||
|
|
|||||||||||
| nedo (31) | |
| Is matchRight a member of the class csField? Same with pushWord. From your definition it's apears they are distinct functions, not members of those classes. In this case "this" has no meaning. Could you please clarify that? | |
|
Last edited on
|
|
| Doth (14) | |||
|
Both of them are members of csField. This is the header file. Also I'm not sure if it's important but I'm writing is as seperate files having a header file and a source file but currently I'm writing everything into the header file and will convert all the big methods into the seperate .cpp file. All the match_ methods are private because they are called by solve() and the user shouldn't call them seperately. I made seperate methods because solve() was getting too chaotic.
| |||
|
Last edited on
|
|||
| Doth (14) | |
|
OK, I found the mistake. I'm sorry to waste everyones time , this is the worst mistake that I made in my whole life... The method solve() is supposed to change the values of the letters and the found words but in my program I print out the values first AND THEN I call the solve() method... I don't understand how could I oversee this. Sorry | |
|
|
|