I'm trying to use G++ to compile some C++ code. It seems to work fine in other compilers, but for whatever reason, G++ won't produce working output.
Disclosure: This is part of a homework assignment, but I feel like it's more of a compiler issue, since it works in other compilers.
Here's the snippet that's wreaking havoc:
set<int> t1, t2;
It's strange because the following code works just fine:
set<int> *t1 = new set<int>();
set<int> *t2 = new set<int>();
Granted, I have to use ->
instead of .
, but that's expected. The first snippet produces a segmentation fault at runtime. The second does intuitively what I'd expect it to.
Anyhow, behind the scenes, the .cpp
for set
has this:
#include <cstdlib>
#include <iostream>
using namespace std;
template <class T>
set<T>::set() : bag<T>() {}
template <class T>
set<T>::set(const set<T>& b) : bag<T>(b) {}
The .h
looks like this:
#include "bag.h"
template <class T>
class set : public bag<T>
{
public:
set( );
set(const set &b);
// ...
};
#include "set.cpp"
And last but not least, the bag.cpp
and bag.h
files looks like this:
using namespace std;
template <class T>
bag<T>::bag() {
head = NULL;
}
template <class T>
bag<T>::bag(const bag<T>& b) {
// ...
}
and bag.h
:
template <class T>
class bag
{
public:
bag( );
bag(const bag &b);
// ...
};
#include "bag.cpp"
Again, I feel like G++ just hates me, but then again I could be doing something dumb. Just a simple nudge in the right direction would be great.