Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: C++ override function from same base template class with multiple inheritance ambiguous function call

Ravindu Kumarasiri:

I need to call init(int* iNumber) function which is derived from the base class.

BaseClass.h


#pragma once
#include "stdafx.h"
template
class BaseClass
{
public:
BaseClass() {}
virtual ~BaseClass() {}
virtual void init(T* object) = 0;
};

ChildClass.h


#pragma once
#include "BaseClass.h"

class ChildClass : public BaseClass, public BaseClass
{
public:
ChildClass() {}
virtual ~ChildClass() {}
};

ChildClassImpl.h


#pragma once
#include "ChildClass.h"
class ChildClassImpl : public ChildClass
{
public:
ChildClassImpl();
virtual ~ChildClassImpl();
private:
void init(int* iNumber) override;
void init(float* fNumber) override;
};

ChildClassImpl.cpp


#include "stdafx.h"
#include
#include "ChildClassImpl.h"

ChildClassImpl::ChildClassImpl(){}

ChildClassImpl::~ChildClassImpl(){}

void ChildClassImpl::init(int* iNumber)
{
std::cout }

void ChildClassImpl::init(float* fNumber)
{
std::cout }

MainClass


#include "stdafx.h"
#include
#include "ChildClassImpl.h"

using namespace std;

int main()
{
ChildClass* childClass = new ChildClassImpl();
int x = 10;
childClass->init(&x);
cout getchar();
return 0;
}

At compile time this is gives the error


Severity Code Description Project File Line Error
(active) "BaseClass::init [with T=int]" is
ambiguous ConsoleApplication4 d:\Learning\ConsoleApplication4\ConsoleApplication4\ConsoleApplication4.cpp 14

What am I doing wrong here? How could I fix it with minimal changes?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: C++ override function from same base template class with multiple inheritance ambiguous function call

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×