We help IT Professionals succeed at work.

C++ newbie

Ghostrider
Ghostrider asked
on
264 Views
Last Modified: 2010-04-01
Hi this is probably a silly question, but I'm new to c++
and the platform I'm developing on does not seem to support templates fully (maybe not beyond ANSI etc)

Can someone explain to me what this error means:

> ::operator new  may not be a template function:

when trying to compile:

template <class T>
inline
void*
operator new(size_t , T *t)
{
  return t;
}

Cheers

Andy
                         
Comment
Watch Question

Which platform are you using?

Borland 4.5x, 5.0 will support fully.
MS Visual C++ 5 will support fully.
g++ will support fully.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
I didn't see Vengineer's stuff when I answered.  But possibly there is a way around this without changing compilers.  What are you hoping to do with this?  As it stands now it is not needed at all.

Author

Commented:
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?

Author

Commented:
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?

Commented:
You missunderstood me.  I don't mean "there might be a way to make the compiler accept it".  That's not possible.  But I do mean that if you explain what you are trying to achieve, we might be able to come up with a different way to accomplish it that will work.   But O don't know what you are trying to do, so I can't help you come up with a solution.

Commented:
Here's your answer.

A pointer to any type can be converted implicitly to a pointer to type void.  Therefore, the syntax of your placament new operator should be as follows:

    void* operator new(size_t , void* t)
    {
        return t;
    }

Tell me if it helps.

Commented:
But placement new is defined in new.h (or no ,.h?)  I'm assuming Ghostrider is trying to do something else here.

Commented:
The body of the function looks suspiciously like placement new...

Commented:
Ghostrider, what solved your problem?
(You know, for future reference...)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.