I
interec
I have trying to set up a three level inheritance heirarchy (see files
test.h/cpp below). When I compile this code using g++, I get the
following errors:
bash-3.00$ g++ test.cpp
test.cpp: In constructor `Lev2::Lev2(int, int, int)':
test.cpp:33: error: no matching function for call to `Lev0::Lev0(const
void**)'
test.h:27: note: candidates are: Lev0::Lev0(const Lev0&)
test.cpp:6: note: Lev0::Lev0(int)
Can someone please explain whats going on and how I can fix this
problem. Please see code below. If I remove the classes ILev2 and Lev2
everything compiles fine. Thanks
//-------------------------- FILE: test.h --------------------------//
#include <iostream>
#include <iomanip>
class ILev0
{
public:
virtual ~ILev0() {}
virtual void PrintLev0() = 0;
};
class ILev1: public virtual ILev0
{
public:
virtual ~ILev1() {}
virtual void PrintLev1() = 0;
};
class ILev2: public virtual ILev1
{
public:
virtual ~ILev2() {}
virtual void PrintLev2() = 0;
};
class Lev0: public virtual ILev0
{
public:
Lev0(int nNum);
virtual void PrintLev0();
protected:
int m_nNum0;
};
class Lev1: public virtual Lev0, public virtual ILev1
{
public:
Lev1(int nNum0, int nNum1);
virtual void PrintLev1();
protected:
int m_nNum1;
};
class Lev2: public virtual Lev1, public virtual ILev2
{
public:
Lev2(int nNum0, int nNum1, int nNum2);
virtual void PrintLev2();
protected:
int m_nNum2;
};
//-------------------------- FILE: test.cpp ------------------------//
#include "test.h"
//-------
Lev0::Lev0(int nNum)
:m_nNum0(nNum)
{
}
void Lev0:rintLev0()
{
std::cout << "Lev0 Num: " << m_nNum0 << std::endl;
}
//-------
Lev1::Lev1(int nNum0, int nNum1)
:Lev0(nNum0),
m_nNum1(nNum1)
{
}
void Lev1:rintLev1()
{
std::cout << "Lev1 Num: " << m_nNum0 << ", " << m_nNum1 <<
std::endl;
}
//-------
Lev2::Lev2(int nNum0, int nNum1, int nNum2)
:Lev1(nNum0, nNum1),
m_nNum2(nNum2)
{
}
void Lev2:rintLev2()
{
std::cout << "Lev2 Num: " << m_nNum0 << ", " << m_nNum1 << ", " <<
m_nNum2 << std::endl;
}
//---
main()
{
Lev0 *b = new Lev0(10);
b->PrintLev0();
}
//------------------------------------------------------------------//
Never miss a thing. Make Yahoo your homepage.
test.h/cpp below). When I compile this code using g++, I get the
following errors:
bash-3.00$ g++ test.cpp
test.cpp: In constructor `Lev2::Lev2(int, int, int)':
test.cpp:33: error: no matching function for call to `Lev0::Lev0(const
void**)'
test.h:27: note: candidates are: Lev0::Lev0(const Lev0&)
test.cpp:6: note: Lev0::Lev0(int)
Can someone please explain whats going on and how I can fix this
problem. Please see code below. If I remove the classes ILev2 and Lev2
everything compiles fine. Thanks
//-------------------------- FILE: test.h --------------------------//
#include <iostream>
#include <iomanip>
class ILev0
{
public:
virtual ~ILev0() {}
virtual void PrintLev0() = 0;
};
class ILev1: public virtual ILev0
{
public:
virtual ~ILev1() {}
virtual void PrintLev1() = 0;
};
class ILev2: public virtual ILev1
{
public:
virtual ~ILev2() {}
virtual void PrintLev2() = 0;
};
class Lev0: public virtual ILev0
{
public:
Lev0(int nNum);
virtual void PrintLev0();
protected:
int m_nNum0;
};
class Lev1: public virtual Lev0, public virtual ILev1
{
public:
Lev1(int nNum0, int nNum1);
virtual void PrintLev1();
protected:
int m_nNum1;
};
class Lev2: public virtual Lev1, public virtual ILev2
{
public:
Lev2(int nNum0, int nNum1, int nNum2);
virtual void PrintLev2();
protected:
int m_nNum2;
};
//-------------------------- FILE: test.cpp ------------------------//
#include "test.h"
//-------
Lev0::Lev0(int nNum)
:m_nNum0(nNum)
{
}
void Lev0:rintLev0()
{
std::cout << "Lev0 Num: " << m_nNum0 << std::endl;
}
//-------
Lev1::Lev1(int nNum0, int nNum1)
:Lev0(nNum0),
m_nNum1(nNum1)
{
}
void Lev1:rintLev1()
{
std::cout << "Lev1 Num: " << m_nNum0 << ", " << m_nNum1 <<
std::endl;
}
//-------
Lev2::Lev2(int nNum0, int nNum1, int nNum2)
:Lev1(nNum0, nNum1),
m_nNum2(nNum2)
{
}
void Lev2:rintLev2()
{
std::cout << "Lev2 Num: " << m_nNum0 << ", " << m_nNum1 << ", " <<
m_nNum2 << std::endl;
}
//---
main()
{
Lev0 *b = new Lev0(10);
b->PrintLev0();
}
//------------------------------------------------------------------//
Never miss a thing. Make Yahoo your homepage.