Solved

C++ newbie

Posted on 1998-06-09
10
207 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
                         
0
Comment
Question by:Ghostrider
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:VEngineer
Comment Utility
Which platform are you using?

Borland 4.5x, 5.0 will support fully.
MS Visual C++ 5 will support fully.
g++ will support fully.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
Comment Utility
It is saying that the function operator new cannot be defined inside a template.  That is you cannot use templates to define overloaded versions f operator new.  I can't image why that is.  Vissual C++ 5.0 does allow it.   Your code compiles and runs fun.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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.
0
 

Author Comment

by:Ghostrider
Comment Utility
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?
0
 

Author Comment

by:Ghostrider
Comment Utility
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
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.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
But placement new is defined in new.h (or no ,.h?)  I'm assuming Ghostrider is trying to do something else here.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
The body of the function looks suspiciously like placement new...
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
Ghostrider, what solved your problem?
(You know, for future reference...)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now