Solved

C++ newbie

Posted on 1998-06-09
10
215 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
ID: 1165542
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
ID: 1165543
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
ID: 1165544
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
ID: 1165545
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?
0
 

Author Comment

by:Ghostrider
ID: 1165546
It's on the Tandem NSK platform using an ancient compiler, is there any way around this?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1165547
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
ID: 1165548
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
ID: 1165549
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
ID: 1165550
The body of the function looks suspiciously like placement new...
0
 
LVL 11

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 28
Dynamically allocate memory 9 55
White board coding practice 3 77
show out valin of json for debugging in visaul c++ 1 13
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

947 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

23 Experts available now in Live!

Get 1:1 Help Now