|
Just provide a reference to an object of type A to the sort predicate:
class A{
std::vector<B*> m_bs;
struct sort_pB
{
sort_pB(const A& a):a(a){}
bool operator()(B* const pb1,B* const pb2) const
{
}
const A& a;
}
void sort()
{
m_bs.sort(m_bs.begin(),m_bs.end(),sort_pB(*this);
}
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
|
Hi,
I'm using a VC++ 6.0 ATL COM object in a .NET code. The library is registered before usign it.
Everything work correctly if the library is being accessed continuously; the problem appears when it's not accessed for a while (maybe 5 minutes, it has not been completely assumed) so when it's accessed again it returns an exception of a QueryInterface error for the library interface, although the library has not been modified, neither changed or deleted...nothing! the system only has been forgotten for a while...
Any suggestion or good idea?, any knowledge about it?
Thank you in advance,
Edgar
__________________________________________
Edgar Berengena Moreno
Software Engineer
Appeyron Research
|
|
|
|
|
Are you sure that you keep atleast one reference to the object?
Sounds like the object have been recycled...
"Well I'm just a hard working corporate slave, my mind should hate what my body does crave.
Well I'm just a humble corporate slave, driving myself into a corporate grave"
Corporate Slave, SNOG
|
|
|
|
|
Thanks, Stefan,
It's said it's a hidden bug almost solved from Microsoft. There's a hotfix still not published (Q325699) which you can ask for to Microsoft Support, but it's only available for NET english version.
This bug consists of an incorrect behaviour of the garbage collector, which removes the instance of the COM objects unsued after a few time.
I'll try to solve it manually until Microsoft publish the fix for my spanish version, accessing the object between short periods of times.
Thank you again,
Edgar
__________________________________________
Edgar Berengena Moreno
Software Engineer
Appeyron Research
|
|
|
|
|
Hi, everyone!
I meet with the following errors when compiling the
following simple codes. My IDE is VC 6.0.
Here are the codes.
--------
#include <iterator>
#include <fstream>
#include <iostream>
using namespace std;
void main()
{
ifstream ifile ("c:\\file1.txt");
istream_iterator<int, ptrdiff_t=""> r (ifile);
istream_iterator<int, ptrdiff_t=""> s (ifile);
}
--------
Here are the errors.
--------
Compiling...
testSTL.cpp
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MyProjects\testSTL\testSTL.cpp(11) : error C2664: '__thiscall std::istream_iterator<int,int,struct std::char_traits<int=""> >::std::istream_iterator<int,int,struct std::char_traits<int=""> >(class std::basic_istrea
m<int,struct std::char_traits<int=""> > &)' : cannot convert parameter 1 from 'class std::basic_ifstream<char,struct std::char_traits<char=""> >' to 'class std::basic_istream<int,struct std::char_traits<int=""> > &'
A reference that is not to 'const' cannot be bound to a non-lvalue
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MyProjects\testSTL\testSTL.cpp(12) : error C2664: '__thiscall std::istream_iterator<int,int,struct std::char_traits<int=""> >::std::istream_iterator<int,int,struct std::char_traits<int=""> >(class std::basic_istrea
m<int,struct std::char_traits<int=""> > &)' : cannot convert parameter 1 from 'class std::basic_ifstream<char,struct std::char_traits<char=""> >' to 'class std::basic_istream<int,struct std::char_traits<int=""> > &'
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing cl.exe.
testSTL.obj - 2 error(s), 0 warning(s)
--------
How to resolve the trouble?
Thanks in advance,
George
|
|
|
|
|
Next time, check the "Display this message as-is (no HTML)" ooption so that the < and > characters will appear.
You're supplying nonsensical parameters to istream_iterator . Replace with:
istream_iterator<int> r (ifile);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
I have seen several times the istream_iterator
is initialized with the ptrdiff_t parameter.
But why I can not use it here?
Cheers,
George
|
|
|
|
|
The standard set of parameters of istream_iterator is
template <
class T,
class charT = char,
class traits = char_traits<charT>,
class Distance = ptrdiff_t
> istream_iterator; So the ptrdiff_t parameter, if anywhere, should be in the fourth position. (Beware, VC++ 6.0 is non-standard in this respect and expects a maximum of three parameters.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín buddies!
I find out the definitions in VC6.0.
--------
template<class U, class E = char, class T = char_traits<E> >
class istream_iterator
: public iterator<input_iterator_tag, U, ptrdiff_t>
--------
So, if I want to use the parameter ptrdiff_t and read int from a file, how could I assign parameter? <int, ??, ptrdiff_t>? What should be the second parameter?
Thanks in advance,
George
|
|
|
|
|
So, if I want to use the parameter ptrdiff_t and read int from a file, how could I assign parameter?
What do you want to specify ptrdiff_t for?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín pal!
To tell the truth, I myself do not
understand why I should use ptrdiff_t.
I use it simply because I am reading
some codes of a project which is developed
from BC IDE and all the pieces of codes
uses the keyword.
Can you show me how to use ptrdiff_t
in my scenario?
Thanks in advance,
George
|
|
|
|
|
Ignore it; just use istream_iterator<int> . If you want to know more about the additional parameters of istream_iterator read some C++ reference, but usually you won't need them anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
I will follow your advice.
Cheers,
George
|
|
|
|
|
Hi, everyone!
My STL tutorial says,
--------
Assignment through the same value of the iterator should happen only once.
ostream_iterator<int> r (cout);
*r = 0;
*r = 1;
is not a valid code sequence.
--------
But I tried the above code sample, it works OK!
The output is 0 and 1.
What is the meaning of the tutorial?
Thanks in advance,
George
|
|
|
|
|
You've hit undefined behavior. If VC++'s STL implementation happens to work this way, this is only sheer luck, and as you know good luck is something you'd better not count on
So, I suggest you stick to the standard and write:
...
*r++ = 0;
*r++ = 1;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín pal!
I am a newbie of STL. I do not understand
what is your meaning clearly. What means
"undefined behavior"? Can you give me a more
clarified and detailed description of my case?
Thanks in advance,
George
|
|
|
|
|
Undefined behavior means you're not doing things as required and the compiler can do anything it wishes (refusing to compile, show different behaviors in debug/release mode, crash in run-time, etc.)
The rule for output iterators is that you cannot assign a value to an interator more than once without incrementing between wrtie operations.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
Hi, Joaquín buddies!
I have tried your codes. It works OK!
But I still do not understand what is the
theory of output iterator, like the following,
--------
Assignment through the same value of the
iterator should happen only once.
--------
I think my code must have some potential error as you
mentioned. But I do not know what the error is.
Can you explain it to me?
Thanks in advance,
George
|
|
|
|
|
Hi, everyone!
I meet with the following trouble when compiling the
following simple STL program.
The error message is, ostream_iterator undeclared.
My IDE is VC 6.0.
Here are the source codes,
--------
#include "iterator"
#include "iostream"
void main()
{
ostream_iterator<int> r (cout);
*r = 0;
}
--------
Thanks in advance,
George
|
|
|
|
|
|
Thanks, Michael buddies!
George
|
|
|
|
|
ostream_iterator is in the std namespace [^]. In short, a namespace is a scope of which contains one or more related functions/classes/structs. To use members of a namespace you either have to 'import' them (with the nasty using namespace std; --nasty because it pollutes the global scope...read the tutorial for more information) or explicitly prefix each one you use with the namespace's name.
The following should do what you want:
#include <iterator>
#include <iostream>
int main () {
std::ostream_iterator<int> r ( std::cout );
*r = 0;
}
My suggestion is that you read up on the STLs. There are many great books on the subject, as well as some excellent articles on this site.
cheers,
-B
|
|
|
|