![]() |
|
#1
|
|||
|
|||
Classes problemHi everyone!
I'm working on this program that reads the unsorted list into an array, sorts it, inserts and deletes the number. Everything worked fine until I had to break it into classes. Here's the main code: CPP / C++ / C Code:
This is my specification file: CPP / C++ / C Code:
And this is the implementation file: CPP / C++ / C Code:
When I compile it, it gives me the following error messages: warning C4182: #include nesting level is 362 deep; possible infinite recursion fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit If I try to input the /Zm800 in project settings but it returns with this error: fatal error C1014: too many include files : depth = 1024 What am I doing wrong? Thanks in advance. |
|
#2
|
||||
|
||||
|
Wait until you see all the errors on the next level in...
You don't need to do this in your .h file Quote:
You also may want to use inclusion guards on your .h file CPP / C++ / C Code:
This way if you have multiple objects the definition is only included once. Or something of that nature. My compiler (gnu g++ cygwin version) doesn't seem to mind if they are there or not but I think some do. Mostly though, just get rid of the .cpp include and compile it with your main.cpp Code:
That will get you past your problem. If you need help with any more of it let us know. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
|
you'll also need an instance of SortedList before you can call its functions. And your SortedList class is flawed--for example, in getData(), what is inData? I don't see a declaration or a parameter.
|
|
#4
|
||||
|
||||
|
Quote:
Actually there are quite a few problems for the OP to get on, but lets burn that chicken on the other side of the fence when we get there shall we. inData actually is a global in the main.cpp file. So declaring it in the implementation file as: CPP / C++ / C Code:
would take care of that. I think that is the intent, not necesarily the correct way to go about it though. As Requoter said, this is all being moved to using classes they are essentially artifacts off the move. Still some boxes to unpack yet if you will. Requoter, could you provide the test datafile so we are using the same input. Since there is no check to see, and as Uber noted no object created yet, the fact that I have no lab4a.dat is merrily ignored until I run the print routine on no data. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#5
|
|||
|
|||
|
Quote:
The problem is I'm only in the process of studying C++, so my knowledge of it is pretty limited. I was just creating classes the way our instructor told us to and following the book. I really didn't expect it to work the first time. It never does Quote:
It wouldn't let me attach the .dat file here, so I had to go with .txt. |
|
#6
|
||||
|
||||
|
Hello,
I looked over you code and saw a few slight issues. One was that of your fstream file identifiers, and your main calls. I went ahead and created a Makefile to compile your source code, and have tested your program. It works quite nicely on my end after I made a few changes. You can view the new source code called requoter_src.zip. I added comments to the main.cpp and sortedList.h file. I slightly modified sortedList.cpp, but nothing major. I just removed some #include calls. My first change was to move the ifstream and ofstream variables inside your class. That makes things easier to handle. Also, I created a local variable to your class called sList in main(). Lastly I made a default constructor to set count to 0. ISO C++ forbids initialization of non-constant static members inside a class. As in: CPP / C++ / C Code:
You will also notice an #ifndef macros inside the sortedList.h file. The #ifdef (if defined) and #ifndef (if not defined) preprocessor commands are used to test if a preprocessor variable has been "defined". There are two common uses for this, with slightly different patterns. When there are definitions in a header file that can not be made twice, the code below should be used. A header file may be included twice other include files include it, or an included file includes it and the source file includes it again. To prevent bad effects from a double include, it is common to surround the body in the include file with the following (where MYHEADER_H is replaced by a name that is appropriate for your program). CPP / C++ / C Code:
Overall, your code and class was fine except for minor anomolies. If you have any questions, please feel free to ask. - Stack Overflow __________________
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [C] / [C++] tags. Your question may have been asked before, try the search facility. |
|
#7
|
||||
|
||||
|
Ok, a few things, did you get rid of the loop when trying to compile? If so, what are your errors now?
You need to consider how you are handling your global variables inData and outData. Before, they look like they were just globals. Now, you might want to consider changing your class member functions to accept a reference to them. Perhaps it would be better to just add them to your class. Once you get the basics together... nevermind. Looks like Stack runnith over... Good Luck with it. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#8
|
||||
|
||||
|
Ok, a few things to note on Stack's reply.
Quote:
A very good explanation. A good point to remember that that header could be included from a number of locations. In fact, in this small example it is already being included from 2 (main.cpp and sortedList.cpp). Since we want to consider the effects of your header being included by other files you may want to remember that direct includes bring some other fun with them. Quote:
What this has done is force the calling program into taking on the namespace std in total. This is not a great idea generally but really a bad idea in a header. Because of the includes and namespace use in the header your main now is using the standard namespace. How else would the cout work. Another solution would be: CPP / C++ / C Code:
It's a bit more typing but will only include the actual items you are using. Something to definately keep in mind in the header. This also serves as a good reminder of what and from where you are using something. This is also a good example of why you use inclusion guards. Your code is then self sufficient on a per file basis so changes elsewhere won't cause your code (main.cpp in this example) to stop working. Just some things to keep in mind. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#9
|
|||
|
|||
|
Quote:
I've tried your version. It compiles everything, but for some reason wouldn't build it, giving these errors: error LNK2001: unresolved external symbol "public: void __thiscall SortedList: error LNK2001: unresolved external symbol "public: void __thiscall SortedList::Insert(void)" (?Insert@SortedList@@QAEXXZ) error LNK2001: unresolved external symbol "public: void __thiscall SortedList::selSort(void)" (?selSort@SortedList@@QAEXXZ) error LNK2001: unresolved external symbol "public: void __thiscall SortedList: rintIt(void)" (?printIt@SortedList@@QAEXXZ)error LNK2001: unresolved external symbol "public: void __thiscall SortedList::getData(void)" (?getData@SortedList@@QAEXXZ) Debug/lab4b.exe : fatal error LNK1120: 5 unresolved externals |
|
#10
|
|||
|
|||
|
Yay! Got it working. Thanks everyone for your help. I really appreciate it.
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need advice on a disturbing problem | JUNK KED | Open Discussion Forum | 6 | 31-Mar-2005 13:51 |
| problem modifying an array of char in a function | ronin | C Programming Language | 10 | 28-Mar-2005 18:15 |
| Fairly simple classes help please | sammacs | C++ Forum | 0 | 30-Nov-2004 09:58 |
| Apache / PHP problem, maybe output length? | HaganeNoKokoro | Apache Web Server Forum | 2 | 08-Sep-2004 07:22 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 07:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The