my functions all look fine with no errors, but when I go into my main program
and do the following:
1 2 3 4 5 6 7
stack Alpha; //Use of class template 'stack' requires template arguments
//so I tried this
stack<string> Alpha; //Use of class template 'stack' requires template arguments
I still get the same error, I was under the impression that all I had to do was to put in the < > what type of data I wanted, so stack<string> A, or stack<int> B should work but I don't understand the error.
Thank you for the help
***UPDATE
adding the following code got rid of the error, but now I'm wondering if that's even the same thing I'm trying to do
You, however, have something more complex, don't you?
For example, std::list does not have 'myType'.
EDIT:
Note: The interface of the class has a design flaw: it reveals unnecessary details about the implementation. Why should the user of the 'stack' know about 'list'? The value_type of stack and list is the same, is it not? Furthermore, some const-correctness, perhaps?
Therefore:
I think I'm making the program worse messing with it.
The problem might be the way I set up the template in my header file.
The full document is at the link below in case anyone wants to have a look.
The document originally started off as a list class, then it was changed to have typedef so we could use other data types, later stacks, and queues were implemented. Finally, the typedef was supposed to be replaced with a template.
That is still not a compilable example. (We are too lazy to download a zip and all, if we could get errors from online compiler with shorter example code.) You could at least include the "errors" verbatim. Are we entitled to respond "we know the answer" to your "I have an error", just to match the level of detail?
1. Line 5: #include <stdio.h> . For what? Nothing in this header file requires it. Avoid unnecessary includes.
2. You do have ostream, which presumably means std::ostream. For that you need something.
Simple #include <iosfwd> would suffice in principle, for all you need here is forward declaration of std::iostream.
3. Line 6: usingnamespace std;. No. Anyone, who includes this header, is now entitled to file a #metoo rape charge. This using directive has valid, safe uses, but header is not one of them.
Explicitly write std::iostream in the header.
4. There is no list::myType. The list declares only one type: the size_type.
I already did add to my previous post a note about why queue and stack should not mention list. They have their own myType, which should be what is needed anyway.
5. Your template member functions do not have implementations here. One has to provide template implementations with the definitions/declarations for each translation unit.
Lets say you have them separate. You somehow compile the implementations ... for which types? Now I include your header and instantiate list<FUBAR> gaz; Where is the objective code for gaz's methods? If I don't see your implementation templates, then I cannot generate code and you cannot provide precompiled binary, for you cannot possibly know the fine details of class FUBAR.
Now that we know that you have to include implementations, you will need <iostream>. You could have that and <iosfwd>, but why bother?
You cannot require the users to #include <iostream> before they include your templates. That is rude.
I am not able to recreate the problem with a shorter piece of code, so I do apologize for that. The problem seems to be with the combination of the classes and the functions as a whole.
I don't think you guys are too lazy, truth is, just like everyone else, there are more important things to do, family....work..etc. I get it no harm done here
I cannot ask what I do not know since I am not proficient in coding, I am unaware of my errors. Being a teacher, mentor or advisor is not easy and most of the time frustrating. I understand my errors are trivial to most but that's the nature of the beast.
keskiverto #3 LMFAO! this was a good laugh, and I agree but I haven't gotten that far in the book yet.
You have already given me more feedback than my professor has all semester.
Really, guys, I do apologize. I did not realize it was a dick move to post a link to my file. I originally started with one little error, but then something else broke and well the Topic had already started and I wanted to take advantage of the feedback. I'm going to revise my code and take it a portion at a time and see if I can find the culprit.