Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:43:43+00:00 2026-05-26T23:43:43+00:00

My code (not yet released, in file iaca.hh ) is on pastebin: Basile Iaca

  • 0

My code (not yet released, in file iaca.hh) is on pastebin: Basile Iaca C++ new conflict
I’m using GCC 4.6 on Debian/Linux/Sid AMD64 with the C++11 dialect.

g++  -std=c++0x -Wall -Wextra -g -O -flto -I/usr/local/include -o iaca.hh.gch iaca.hh 
iaca.hh:631:2: warning: #warning should implement the methods [-Wcpp]
iaca.hh: In static member function 'static IaDictionnaryItem* IaDictionnaryItem::make()':
iaca.hh:964:46: error: request for member 'operator new' is ambiguous
/usr/local/include/gc/gc_cpp.h:304:14: error: candidates are: static void* gc::operator new(size_t, void*)
/usr/local/include/gc/gc_cpp.h:296:14: error:                 static void* gc::operator new(size_t, GCPlacement)
/usr/local/include/gc/gc_cpp.h:293:14: error:                 static void* gc::operator new(size_t)
iaca.hh:675:7: error:                 static void* IaAnyValue::operator new(size_t, IaAnyValue::allocate_new_value_st)
iaca.hh:667:7: error:                 static void* IaAnyValue::operator new(size_t, size_t, IaAnyValue::allocate_new_value_st)

I can’t figure out what is the right syntax for forcing operator new. I want the one from my class IaAnyValue to be called in my function IaDictionnaryItem::make at the end of my iaca.hh file

I’ve introduced the empty allocate_new_value to solve the ambiguity, without success.

I tried without success

IaDictionnaryItem* IaDictionnaryItem::make() {
  return new(IaAnyValue::allocate_new_value) IaDictionnaryItem;
}

and

IaDictionnaryItem* IaDictionnaryItem::make() {
  return IaAnyValue::operator new(IaAnyValue::allocate_new_value) IaDictionnaryItem;
}

From what I know, the operator new is always called with sizeof (*this) as implicit first argument, etc.

Some motivations about my question is in this question about Boehm’s GC & C++. Please, don’t tell me I should not use Boehm’s GC. I need to use it (otherwise I won’t use C++).

What is the right syntax to force the good operator new to be called?

I want the Boehm’s GC allocator to be used. It is available thru the gc_cleanup class, which is in class IaItemValue : public IaAnyValue, gc_cleanup and also as the new in my class IaAnyValue (the only super-class of IaDictionnaryItem) I agree there is ambiguity, I just don’t guess the syntax to force it.

So how should I code my trivial IaDictionnaryItem::make at the end of the file to get it compiled successfully?

For readability, I would prefer calling IaAnyValue::operator new with sz=sizeof(*this) i.e. sizeof(IaDictionnaryItem), gap=0 and al=allocate_new_value. I just can’t figure out the syntax to force this particular one to be called (of course, I still want the constructor of IaDictionnaryItem to be called inside IaDictionnaryItem::make).

I’ve tried to force the gc::operator new(size_t size, GCPlacement gcp) (the gc class is inherited by  gc_cleanup from <gc/gc_cpp.h>) using

IaDictionnaryItem* IaDictionnaryItem::make() {
  return new (UseGC) IaDictionnaryItem;
}

My make function is a static function returning a new instance of my object. Remember that I’m using Beohm’s GC, and it will eventually release the memory used (and delete the object) when no pointers point to it.

But I’m still getting

iaca.hh: In static member function 'static IaDictionnaryItem* IaDictionnaryItem::make()':
iaca.hh:962:22: error: request for member 'operator new' is ambiguous
/usr/local/include/gc/gc_cpp.h:304:14: error: candidates are: static void* gc::operator new(size_t, void*)
/usr/local/include/gc/gc_cpp.h:296:14: error:                 static void* gc::operator new(size_t, GCPlacement)
/usr/local/include/gc/gc_cpp.h:293:14: error:                 static void* gc::operator new(size_t)
iaca.hh:675:7: error:                 static void* IaAnyValue::operator new(size_t, IaAnyValue::allocate_new_value_st)
iaca.hh:667:7: error:                 static void* IaAnyValue::operator new(size_t, size_t, IaAnyValue::allocate_new_value_st)

Regards.

EDIT: Here is simple example of the problem:

#include <cstddef>
struct A {};
struct B { void* operator new(std::size_t, A); };

struct C {};
struct D { void* operator new(std::size_t, C); };

struct E : B, D {};

int main()
{
    //I want to use `void* D::operator new(std::size_t, C);` to allocate memory
    //but it will not compile because the call to operator new is ambiguous.
    new(C()) E;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:43:44+00:00Added an answer on May 26, 2026 at 11:43 pm

    Your problem is a multiple inheritance issue. Notice that the class IaItemValue inherits from both IaAnyValue and gc_cleanup (and IaDictionnaryItem inherits from IaItemValue), both of which provide overloads for operator new. In order to resolve this, you can add the following line to the class definition for IaDictionnaryItem:

    using IaAnyValue::operator new;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've inherited a ASP/VB6 code base (not my forte... yet) and I'm trying tease
I'm trying to test code around a web service that is not available yet.
I've been reading code complete, not far in yet but one of the things
Why does the following code not work as I was expecting? <?php $data =
Our Java code (not the test code) reads files from the current directory, which
Why does the following code NOT give an error, nor any type of a
my jquery code not run with IE6 but runs all others including IE7. It
Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
Why does this code not print an exception stack trace? public class Playground {
Why is the following C# code not allowed: public abstract class BaseClass { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.