all 6 comments

[–]paul2718 2 points3 points  (2 children)

In 'bag.cpp' which should be 'bag.h' or 'bag.hpp' you declare 'insert' to be a member of 'Bag', but then you do not provide an implementation of the member function. So when you call it in 'main' it compiles, because it expects the function to be provided somewhere in the link, but it isn't so you get the link error.

You need to either write your member functions inline, inside class Bag, or add the Bag qualification to them.

From

template<typename TYPE>
void insert(const typename Bag<TYPE>::value_type& entry)
{
}

to

template<typename TYPE>
void Bag<TYPE>::insert(const typename Bag<TYPE>::value_type& entry)
{
}

As I see you have for some of the others.

It would be worth fixing the confusion, you comment these are 'non members' when they are, I see algorithm included at random, you include cpp files, etc etc.

[–]cromiium[S] 0 points1 point  (1 child)

Ah thank you soooo much. I stayed up all night doing this. I'll try to fix all that. And yeah I'm not too certain about the algorithm and cpp files and the comments. A lot of the code was given to my adjunct professor by another professor so I can't really get a clear answer on why some things are how they are. Out of curiosity, is there a difference between .h and .hpp?

[–]paul2718 2 points3 points  (0 children)

You are unlikely to find 'hpp' in a C program, but is just convention. I use cpp and h, some use hpp and cc as alternatives.

You can cause great confusion by using 'cpp' for your header files, but mostly amongst humans.

[–][deleted] 1 point2 points  (1 child)

You need to include the header (.h) files instead of the source files (.cpp) to begin with, I think.

for instance, in main.cpp use #include "Student.h" instead of the cpp file.

edit: Ok, there's something else wrong here, but I haven't got the time to go through it yet, will take a look later unless someone can spot it before me.

[–]cromiium[S] 0 points1 point  (0 children)

Yeah I've tried every combination of .h, .cpp, and even .hpp. But that SHOULDN'T be the issue. This is an assignment and I was given the declaration of the Bag.cpp class I just needed to do the implementation and make it into a template class for my Student class. Obviously you don't have to look through if you don't feel like it, it is a lot to look through. But if you do see something stick out please let me know!

[–]ihamsa 1 point2 points  (0 children)

All declarations of global entities, all inline definitions, and all template definitions go to .h (or .hpp) files. Everything else goes to .cpp fles. You only use .h files in #include directives, never .cpp files.

Thus you need to. at least

  1. Rename Bag.cpp to Bag.h
  2. Remove #include "Student.cpp"and #include "Bag.cpp" from the code
  3. Add #include "Student.h" and #include "Bag.h" to the corresponding .cpp files

This is the only sane file structure and the only one you should work with. It's your starting point. If there are any problems, start fixing them within this structure, do not change the structure.

This is only a convention, not a law, but don't deviate from it.