|
Hi, everyone!
I meet with some trouble when debugging the following
codes dealing with overloading operator >> in STL.
I have tried my best to resolve it but still failed.
My IDE is VC6.0.
Source Codes:
--------
#include <iostream>
#include <map>
#include <set>
using namespace std;
class employee_data {
public:
employee_data() : name (""), skill(0), salary(0) {}
employee_data(string n, int s, long sa) :
name (n), skill (s), salary (sa) {}
string name;
int skill;
long salary;
friend ostream& operator<< (ostream& os, const employee_data& e);
};
ostream& operator<< (ostream& os, const employee_data& e) {
os << "employee: " << e.name << " " << e.skill << " " << e.salary;
return os;
}
class employee {
public:
employee (int i, employee_data e) :
identification_code (i), description (e) {}
int identification_code; // key expression to identify an employee
employee_data description;
bool operator< (const employee& e) const {
return identification_code < e.identification_code; }
};
int main()
{
set <employee, less<employee> > employee_set;
multiset <employee, less<employee> > employee_multiset;
employee_data ed1 ("john", 1, 5000);
employee_data ed2 ("tom", 5, 2000);
employee_data ed3 ("mary", 2, 3000);
employee e1 (1010, ed1);
employee e2 (2020, ed2);
employee e3 (3030, ed3);
pair<set <employee, less<employee> >::iterator, bool>
result = employee_set.insert (e1);
if (result.second) cout << "insert ok"; else cout << "not inserted";
cout << endl << (*result.first).description.name << endl;
result = employee_set.insert (e1);
if (result.second) cout << "insert ok"; else cout << "not inserted";
return 1;
}
--------
Error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(22) : error C2679: binary '<<' : no operator
defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class
std::allo
cator<char> >' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(56) : error C2679: binary '<<' : no operator
defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<
char> >' (or there is no acceptable conversion)
--------
How to resolve them?
Thanks in advance,
George
|
|
|
|
|
You forgot to #include <string> .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie!
George
|
|
|
|
|
Subject.
I just cant think of where to start from. I guess i should inherit WTL CTreeViewCtrl, and add functionality for parsing computers directory tree.
So would you be so kind to give me links to samples of doing that?
Any help would be appreciated, thanks.
Sincerely yours, Ilya Kalujny.
|
|
|
|
|
SHBrowseForFolder might work for you
|
|
|
|
|
Yeah, but isnt it modal?
When i try to use it like this:
BROWSEINFO bi = { 0 };
bi.lpszTitle = _T("Pick a Directory");
bi.hwndOwner = m_hWnd;
LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
if ( pidl != 0 )
{
// get the name of the folder
TCHAR path[MAX_PATH];
if ( SHGetPathFromIDList ( pidl, path ) )
{
}
// free memory used
IMalloc * imalloc = 0;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->Free ( pidl );
imalloc->Release ( );
}
}
I Get a modal dialog that is definitely not what i want
Well, if only i had a possibility to modify that dialog somehow (ie. insert my onw controls and write according handlers) that would be nice, but how??
More hints pleaaaase
Sincerely yours, Ilya Kalujny.
|
|
|
|
|
This is a simple question, i hope that someone can answer. I have created an ATL projectand want to expose function from the interface. I want to accept string as an argument to this function. The problem is that i don't know how to give the input parameters. I am trying [in] char * num but it is not working. Can any one tell me how can i accept string ??
|
|
|
|
|
Conventionally, you use a BSTR type instead. This is a wide string (or UNICODE), and is dealt with in VC++ quite happily by using one of the wrapper classes _bstr_t or CComBSTR.
If you want to call your function from VB, then this is compatible.
Steve S
[This signature space available for rent]
|
|
|
|
|
How do I find the maximum value in a collection as well as the array (vector) index of that value?
e.g. a vector
[1, 5, 3, 6, 8, 2]
I want to find the largest value (8) but I also want to find its index (4).
I can use the max_element algorithm to get the value. What about the index?
Kevin
|
|
|
|
|
upper_bound should do the job
Ryan
They read good books, and quote, but never learn
a language other than the scream of rocket-burn.
Our straighter talk is drowned but ironclad;
elections, money, empire, oil and Dad.
|
|
|
|
|
|
I've an in-proc COM object that is registered on the client PC from a network share. An app that uses this COM object running out the same network share shows marked performance degradation (upto 2-3 times slow) when compared to running the same app with the COM object registered locally (the dll was copied to a local drive).
Neither the app nor the the COM object access any files over the network other than some initial setup that happens at load time.
I was expecting a delay only during app load time compared to the local install case, but it turns out that as the network traffic increases, the app starts to lag behind in processing time sensitive events (sometimes upto 20 minutes behind!). Also interesting to note is that as the network traffic reduces, the app starts to catch up & events get handled in timely fashion.
Anybody experienced similar behavior wrt COM objects being registered from a network share? Any insights?
Chen Venkataraman
|
|
|
|
|
I have some code like this
MyClass MyObject;
vector<int> t;
for ( int i=0; i<5; i++)
t.push_back(i+100);
for ( it=t.begin(); it != t.end(); it++)
{
if ( MyObject.GetIntValue() == (*it)
t.erase(it);
}
where i am doing erase operation for current iterator on a vector.
This loop crashes somewhere in
template<class _init,
="" class="" _outit=""> inline
_OutIt _Copy_opt(_InIt _First, _InIt _Last, _OutIt _Dest,
_Nonscalar_ptr_iterator_tag)
{ // copy [_First, _Last) to [_Dest, ...), arbitrary iterators
for (; _First != _Last; ++_Dest, ++_First)
*_Dest = *_First;
return (_Dest);
Any idea what i am doing wrong?
|
|
|
|
|
The problem is that the call to erase invalidates it , so you can no longer use it for the remaining of the loop. Wou can fix this by noticing that vector::erase returns an interator to the following element:
for ( it=t.begin(); it != t.end(); )
{
if ( MyObject.GetIntValue() == (*it)
it=t.erase(it);
else
++it;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, everyone!
Look at the following descriptions from a book,
--------
template <class Key, class T, class Compare = less<Key>,
template <class U> class Allocator = allocator>
class map {
typedef Key key_type;
typedef pair<const Key, T> value_type;
...
};
--------
I do not understand the following starnge C++ grammar,
--------
template <class U> class Allocator = allocator
--------
It really makes me mad!
What does it mean? Who can give me a description?
Thanks in advance,
George
|
|
|
|
|
This is called a template template parameter, i.e. a template parameter which is not a true type, but rather a template (in your particular case, accepting one parameter).
The code is a little strange cause when STL was defined template template parameters weren't part of C++, so STL uses an alternate trick (see allocator::rebind ).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie, my old friend!
George
|
|
|
|
|
Is it safe to use CAtlArray to store an array of structures in a program that just uses Win32 API (we don't use MFC or any other framework). I've tried implementing it and too my surprise it just worked. I'm looking for the catch. Is it safe to re-use the same array repeatedly or will it eat memory each time I use the array.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
I got an out-of-proc automation server developed using ATL. I want to use it in dialog based MFC application. For this purpose i normally use tlb file to generate class.
Now the problem is that this component fires events and i don't know how to get events fired from control in MFC app. In case of ActiveX control it was easy, as i just right click on control and add event. How can i do so in fore said case ???
|
|
|
|
|
Normally this is done by creating a simple event sink and then using Advise/Unadvise to connect the sink to the object. I'm sure there's an example of this in MSDN.
Steve S
[This signature space available for rent]
|
|
|
|
|
This project http://codeproject.com/wtl/TabbingFramework.asp[^]
uses the Sink Event map and the DispAdvise/UnAdvise.
Look in the HtmlFrame.h
public:<br />
BEGIN_SINK_MAP(CHtmlFrame)<br />
SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_TITLECHANGE, OnTitleChange, &TitleChangeInfo)<br />
SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, OnNavigateComplete2, &NavigateComplete2Info)<br />
SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete, &DocumentCompleteInfo)<br />
END_SINK_MAP()
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Hi, everyone!
A book said,
--------
a deque supports the constant time execution of these operations
at the end as well as at the beginning.
Insert and erase in the middle take constant time.
--------
I think the insert and rease in the middle algorithm of
STL deque does not take constant time. The time it
taken can be descripted as O(n). (Since deque is stored as a
linked list and not an array.)
I think only an algorithm takes O(1) time should be treated as
"constant time" algorithm.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
I think that is an error in the book. deque is linear insert/remove in the middle according to my stuff.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddie!
George
|
|
|
|
|
Hey all,
Some doubts:
1- How to make a property of an Activex Control(VC++), shows up at the "properties window" in Visual Basic.
2- How to set up the design-time image resource that will be drawn that represents the Control on the form, when the user drag it from the toolbox to the form. I know it's inside the OnDraw() event, isn't it?
Remebering...all without MFC, just ATL.
Raphael Amorim Dantas Leite
VC++, VB, Java, .NET and eMbedded Programmer
|
|
|
|
|