C
cppsks
Here is the code that I am working with:
#include <new>
#include <iostream>
#include "stdlib.h"
class Base1
{
public:
Base1() { cout << "Base1:" << this << endl; }
void* operator new(size_t size) throw (std::bad_alloc) { cout << "operator
Base1::new\n"; return malloc(size); } // line 9
void operator delete(void* ptr) throw() { cout << "operator
Base1::delete\n"; free(ptr); }
};
class Base2
{
public:
Base2() { cout << "Base2:" << this << endl; }
void* operator new(size_t size) throw (std::bad_alloc) { cout << "operator
Base2::new\n"; return malloc(size); }// line 17
void operator delete(void* ptr) throw() { cout << "operator
Base2::delete\n"; free(ptr); }
};
class SubClass : public Base1,
public Base2
{
public:
SubClass() { cout << "SubClass:" << this << endl; }
};
class SubClass1 : public Base2,
public Base1
{
public:
SubClass1() { cout << "SubClass1:" << this << endl; }
};
int main()
{
cout << "\n===================\n";
new SubClass; // line 39
}
// Here is the output from the compiler:
ambiguous.cc: In function `int main()':
ambiguous.cc:39: request for member `operator new' is ambiguous
ambiguous.cc:17: candidates are: static void * Base2:perator new(unsigned
int)
ambiguous.cc:9: static void * Base1:perator new(unsigned
int)
ambiguous.cc:39: confused by earlier errors, bailing out
What options do I have in order to resolve this conflict? Please assume that
removing multiple inheritance is not an option.
Thanks.
#include <new>
#include <iostream>
#include "stdlib.h"
class Base1
{
public:
Base1() { cout << "Base1:" << this << endl; }
void* operator new(size_t size) throw (std::bad_alloc) { cout << "operator
Base1::new\n"; return malloc(size); } // line 9
void operator delete(void* ptr) throw() { cout << "operator
Base1::delete\n"; free(ptr); }
};
class Base2
{
public:
Base2() { cout << "Base2:" << this << endl; }
void* operator new(size_t size) throw (std::bad_alloc) { cout << "operator
Base2::new\n"; return malloc(size); }// line 17
void operator delete(void* ptr) throw() { cout << "operator
Base2::delete\n"; free(ptr); }
};
class SubClass : public Base1,
public Base2
{
public:
SubClass() { cout << "SubClass:" << this << endl; }
};
class SubClass1 : public Base2,
public Base1
{
public:
SubClass1() { cout << "SubClass1:" << this << endl; }
};
int main()
{
cout << "\n===================\n";
new SubClass; // line 39
}
// Here is the output from the compiler:
ambiguous.cc: In function `int main()':
ambiguous.cc:39: request for member `operator new' is ambiguous
ambiguous.cc:17: candidates are: static void * Base2:perator new(unsigned
int)
ambiguous.cc:9: static void * Base1:perator new(unsigned
int)
ambiguous.cc:39: confused by earlier errors, bailing out
What options do I have in order to resolve this conflict? Please assume that
removing multiple inheritance is not an option.
Thanks.