Inspired by GoTW 101, I decided to try and apply the Pimpl idiom to a part of a library I'm working on using the pimpl wrapper described there.
However, when trying to compile, I get an undefined reference to the destructor of that Pimpl class. This only happens with clang and only on Linux. I.e., GCC on Linux and Clang on OSX work fine.
Here's the code that's not working:
Header file
#ifndef TANK_MUSIC_HPP
#define TANK_MUSIC_HPP
#include <string>
#include "../Utility/Pimpl.hpp"
namespace tank
{
class Music
{
struct impl;
Pimpl<impl> data;
public:
Music(std::string fileName);
//~Music();
bool load(std::string fileName);
void play();
void pause();
void stop();
};
}
#endif //TANK_MUSIC_HPP
Source file
#include "Music.hpp"
#include "../System/Game.hpp"
#include <SFML/Audio/Music.hpp>
#include "../Utility/Pimpl_impl.hpp"
namespace tank
{
struct Music::impl {
sf::Music music;
bool loaded = false;
};
Music::Music (std::string fileName)
{
load(fileName);
}
//Removing this comment works, but this shouldn't be necessary should it?
//Music::~Music() = default;
bool Music::load (std::string fileName)
{
if (data->loaded)
{
Game::log << "Music already loaded!" << std::endl;
return data->loaded;
}
data->loaded = data->music.openFromFile(fileName);
return data->loaded;
}
void Music::play()
{
data->music.play();
}
void Music::pause()
{
data->music.pause();
}
void Music::stop()
{
data->music.stop();
}
}
Any ideas would be appreciated, this has had me scratching my head for a while now!