Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto_ptr compile error

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
auto_ptr does not compile in BCB5
The first sample generates an error the second compiles allright.

// !!! #include <memory>
std::auto_ptr<char> buf;
buf = std::auto_ptr<char>(new char[1024]);


// !!! #include <memory>
std::auto_ptr<char> buf = std::auto_ptr<char>(new char[1024]);

The code I am working on has a declaration in a header and assignment in cpp.

How to proceed ?

hennep

P.S. please don't tell me to compile it with VC (this works).
 
There is a problem regarding the way auto_ptr is defined in C++ Builder STL implementation.

try this:

std::auto_ptr<char> buf2(new char[1024]);
std::auto_ptr<char> buf;
buf = buf2;

I can not check it with your compiler version but it should work.
 
thanks, your solution works but the rest of the project fails.

header file:
std::auto_ptr<char> samplebuf1;

cpp file
std::auto_ptr<char>dummy1 = std::auto_ptr<char>(new char[buflen*2]);
samplebuf1 = dummy1;

The code compiles now, but the rest of the project is a big mystery to me.


I tried to compile a project from doctor jobbs journal.
If anybody is interested in recording and playing sound with the windows api. I have zipped the project and the original code from ddj is included.
hennep

Please let me know if you can make this work in bcb
 
You shouldn't use auto_ptr with arrays. The destructor calls delete, not delete[], so you'll get a memory leak. Use a vector instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top