Re: Problem with dynamic creation of PmStream
Roger Dannenberg <
rbd@...>
2011-02-19 14:07:28 GMT
I think this is basically a problem of trying to use a C library as
a C++ library. What are you trying to do? If you just want to create
a vector of PmStream, I think you can set the vector length at
creation time or after creating it. You don't need to construct it
incrementally/iteratively by calling push_back() n times.
If you want to open streams and add them to the list, then do
something like:
PmStream *s;
if (Pm_OpenOutput(&s, ...) == pmNoError) {
v.push_back(s);
}
In C++, you might expect that if you delete a vector, the components
of the vector will be properly deallocated, but since the components
here are just pointers, you'll have to explicitly call Pm_Close() on
each vector element before deleting the vector.
This could be handled by "smart pointers" similar to C++ strings,
but I think that's overkill for a simple problem (unless someone
wants to fully wrap PortMidi as a C++ class, similar to the Java
API).
-Roger
Hi,
I
have a std:vector of PmStream* but I can’t figure out a way
to create the stream objects on-the-fly. Here’s my code:
Int
streamcount = some_value;
int
i;
std::vector
< PmStream*> v;
for
(i = 0; i < streamcount; i++)
{
//
VS2010 reports error C2469: 'new' : cannot allocate 'void'
objects with the following line
PmStream*
s = new PmStream();
v.push_back(s);
}
Can anybody see where I’m going wrong,
please? My research on the net would seem to indicate that
using “new” to create instances of a void (abstract) class
isn’t allowed, but I can’t find a work-around.
Best wishes.
Tim Burgess
Raised Bar Ltd
Phone: +44 (0)1827 719822
Don't forget to vote for improved
access to music and music technology at
http://www.raisedbar.net/petition.htm
_______________________________________________
media_api mailing list
media_api-Ayv8T2snMLBt9CRQqspbbg@public.gmane.org
http://lists.create.ucsb.edu/mailman/listinfo/media_api
_______________________________________________
media_api mailing list
media_api@...
http://lists.create.ucsb.edu/mailman/listinfo/media_api