Use new with already allocated memory.

Posted on 2002-04-29
Last Modified: 2010-04-02
I'm trying to use new with memory that already been allocated, but I keep getting a compile error.

new ((void*)SomePtr) T(NewValue);

T is a template type.
Question by:CuriousGeorge916
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 6976942
Please post your code and error you are getting
LVL 30

Accepted Solution

Axter earned 150 total points
ID: 6976953
Did you use include <new>?
#include <new>

Author Comment

ID: 6976974
The complete code is to large, and the function that contains the above code I posted only has two lines of code.
void push_back(const T& NewValue)
 new ((void*)ptr+VSize) T(NewValue);

Author Comment

ID: 6976976
>>Did you use include <new>?
No, I didn't.

Do I have to use std::new with this?
LVL 30

Expert Comment

ID: 6976979
>>Do I have to use std::new with this?

Not on my compiler.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

751 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