Solved

Use new with already allocated memory.

Posted on 2002-04-29
5
181 Views
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.
0
Comment
Question by:CuriousGeorge916
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

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

Accepted Solution

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

Author Comment

by:CuriousGeorge916
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)
{
 MakeSpaceForNew();
 new ((void*)ptr+VSize) T(NewValue);
}
0
 

Author Comment

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

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

Expert Comment

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

Not on my compiler.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

830 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