I have a base class.
#include <string.h>
class Channel
{
private:
std::string stdstrName;
public:
Channel() : stdstrName("CHANNEL"){ }
Channel(std::string name) : stdstrName(name){ }
void PrintName() { std::cout << stdstrName << std::endl; }
};
which is inherited by Position class.
class PositionChannel : public Channel
{
public:
std::vector<int> keyframes;
PositionChannel() : Channel("POSITION") , keyframes( { 1 , 2, 3 }) { }
};
There is a director class which has the channel clas as its data members.
#include "Channel.h"
#include <memory>
class Director
{
private:
std::vector<std::shared_ptr<Channel>> channels;
public:
void AddChannel(std::shared_ptr<Channel> chn) { channels.push_back(chn); }
void GetChannel(Channel **chn) { *chn = channels[0].get(); }
};
now when in the main function.
// Free function
template<typename T>
void GetChannel(Director *dir)
{
T *chn;
dir->GetChannel(&chn);
}
Director dir;
PositionChannel channel;
std::shared_ptr<Channel> channelPointer = std::make_shared<Channel>(channel);
dir.AddChannel(channelPointer);
GetChannel< PositionChannel>(&dir); // here i get error
this is the error message error C2664: ' cannot convert argument 1 from 'T **' to 'Channel **
if i change the templated function to a non templted function than i do not get any error.