|
Uninitialized storage is basically storage that has been allocated but not initialized. Imagine doing a "new [n] char". You have allocated char array, but the contents of the array is uninitialized.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
In my first example, I do not understand why the
storage that has been allocated but not initialized.
Can you give me an explanation?
Thanks in advance,
George
|
|
|
|
|
The allocate method is just a fancy malloc. All it does is reserve the space, it doesn't actually do anything to the memory.
It is sort of like building a road. First you must acquire the land to build the road. This is the allocation step. But just because you have acquired the land doesn't mean you have a road. The land is still "uninitialized". It isn't until you actually build the road that you have a fully "initialized" road.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
I do not understand why in example 1, (int*)0 is
used as the second parameter of allocate. What is the
meaning of (int*)0 here?
Thanks in advance,
George
|
|
|
|
|
First of all, a remark: the tutorial you're using is grossly outdated, there is no global allocate function, since C++ 98' standard this function is a member of std::allocator .
Now, the second parameter is a hint pointer, optionally used by the allocation engine to improve performance. If no hint is to be provided, the null pointer (0) can be passed. Now, consider the situation:
allocate(1,0); This cannot work because allocate does not know which kind of type you're allocating memory for. The ambiguity can be solved in one of these two forms:
allocate<int>(1,0);
allocate(1,(int*)0);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
For specialized allocation systems, the address could be used to tell which heap to use as the source of the allocation.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddie!
George
|
|
|
|
|
Thanks, Joaquín buddie!
George
|
|
|
|
|
I'm trying to advise to HTMLElementEvents2
class declaration has the folowing line:
public IDispEventImpl<2,CTBar,&__uuidof(HTMLElementEvents2),&LIBID_MSHTML, 1, 0>
Here's body of OnDocumentComlete:
HRESULT __stdcall CTBar::OnDocumentComplete(IDispatch* pDisp, VARIANT* URL)<br />
{<br />
IDispatch* dispdoc;<br />
IWebBrowser2* wb;<br />
pDisp->QueryInterface(IID_IWebBrowser2,(LPVOID*)&wb);<br />
wb->get_Document(&dispdoc);<br />
dispdoc->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&hDoc);<br />
hDoc->get_body(&hBody);<br />
HRESULT hr=_IDispEventLocator<2, &__uuidof(HTMLElementEvents2)>::DispEventAdvise( hBody, &__uuidof(HTMLElementEvents2));<br />
return S_OK;<br />
}
As a result i'm getting E_NOINTERFACE in hr. Why? Where's error?
|
|
|
|
|
It could be because you're not defining the proper version number in your class declaration. I've had the same problem trying to sink web browser events.
Try setting the MSHTML version to 4.0:
public IDispEventImpl<2,CTBar,&__uuidof(HTMLElementEvents2),&LIBID_MSHTML, 4, 0>
HTH,
scott.
|
|
|
|
|
Tried, no effect!
Any other suggestions?
|
|
|
|
|
Hi, everyone!
Here is a sample of the usage of allocate of STL.
When compiling it with VC6.0, some error occur.
I have added the source codes and related error
messages below.
Source:
--------
#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
int main()
{
vector<int> a (2, 5);
vector<int> b (2, 7);
int *c = allocate((ptrdiff_t) a.size(), (int*)0 );
transform ( a.begin(), a.end(), b.begin(),
raw_storage_iterator<int*, int> (c), plus<int>() );
copy (&c[0], &c[2], ostream_iterator<int> (cout, " ") );
return 1;
}
--------
Error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testRawIterator\testRawIterator.cpp(12) : error C2065: 'allocate' :
undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\testRawIterator\testRawIterator.cpp(12) : error C2440: 'initializing' :
cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
--------
How to resolve the trouble?
Thanks in advance,
George
|
|
|
|
|
alllocate() is supposed to be a member function of your special allocator class, not a global function.
PS. I think you should get this book.
|
|
|
|
|
I'm trying to retrieve the Url of a new window for my BHO... I did what S.Rod. suggested (his code was in C#, I'm using C++/ATL)
case DISPID_NEWWINDOW2:
{
CComPtr<IDispatch> pDisp = NULL;
m_pBlankDlg = new CBlankDlg();
m_pBlankDlg->Create( NULL );
CComPtr<IUnknown> spUnk;
m_pBlankDlg->GetDlgControl( IDC_BROWSER, IID_IWebBrowser2, (void **) &spUnk );
CComQIPtr<IWebBrowser2> spWB = spUnk;
spWB->get_Application( &pDisp );
pDispParams->rgvarg[1].pdispVal = pDisp;
m_pBlankDlg->ShowWindow( SW_SHOW );
}
And in CBlankDlg :
class CBlankDlg :
public CAxDialogImpl<CBlankDlg>,
public IDispEventImpl<IDC_BROWSER,CBlankDlg>
{
...
BEGIN_SINK_MAP(CBlankDlg)
SINK_ENTRY(IDC_BROWSER, 250, BeforeNavigate2Browser)
END_SINK_MAP()
void __stdcall BeforeNavigate2Browser(LPDISPATCH pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, BOOL* Cancel);
The BeforeNavigate2 event is never triggered... why?
thanks for your help!
---------------
Tired of Spam? Introducing InboxShield® for Microsoft® Outlook®
http://www.edovia.com
|
|
|
|
|
Fixed it!
spWB->get_Application(&pIDispatch);
*(pDispParams->rgvarg[1].ppdispVal) = pIDispatch;
---------------
Tired of Spam? Introducing InboxShield® for Microsoft® Outlook®
http://www.edovia.com
|
|
|
|
|
I got it to work by changing this line:
*(pDispParams->rgvarg[1].ppdispVal) = pIDispatch;
But this cancels the popup! What I want to do is to get the URL and let the popup show itself. Why won't it display?
void __stdcall CBlankDlg::BeforeNavigate2Browser(LPDISPATCH pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
CAtlString szUrl = *URL;
*Cancel = FALSE;
}
---------------
Tired of Spam? Introducing InboxShield® for Microsoft® Outlook®
http://www.edovia.com
|
|
|
|
|
Hi, everyone!
Here is a sample of the usage of inserter of STL.
When compiling it with VC6.0, some error occur.
I have added the source codes and related error
messages below.
Source:
--------
#include <iostream>
#include <vector>
#include <deque>
#include <fstream>
#include <algorithm>
using namespace std;
template <class Container>
back_insert_iterator<Container> back_inserter(Container& x) {
return back_insert_iterator<Container>(x);
}
template <class Container>
front_insert_iterator<Container> front_inserter(Container& x) {
return front_insert_iterator<Container>(x);
}
template <class Container, class Iterator>
insert_iterator<Container> inserter(Container& x, Iterator i) {
return insert_iterator<Container>(x, Container::iterator(i));
}
int main()
{
ifstream f ("c:\\example"); // file example: 1 3
deque<int> d;
copy (istream_iterator<int>(f),
istream_iterator<int>(),
back_inserter(d) );
vector<int> w (2,7);
copy (w.begin(), w.end(), front_inserter (d) );
insert_iterator<deque<int> > i = inserter (d, ++d.begin() );
*i = 9;
return 1;
}
--------
Error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(31) : error C2667: 'back_inserter' : none of 2 overload
have a best conversion
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(31) : error C2668: 'back_inserter' : ambiguous call to
overloaded function
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(34) : error C2667: 'front_inserter' : none of 2 overload
have a best conversion
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(34) : error C2668: 'front_inserter' : ambiguous call to
overloaded function
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(36) : error C2667: 'inserter' : none of 2 overload have a
best conversion
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(36) : error C2668: 'inserter' : ambiguous call to
overloaded function
C:\Program Files\Microsoft Visual Studio\MyProjects\testI\testI.cpp(36) : error C2512: 'insert_iterator<class
std::deque<int,class std::allocator<int> > >' : no appropriate default constructor available
Error executing cl.exe.
--------
Thanks in advance,
George
|
|
|
|
|
Why are you defining back_inserter and family in your program? They are already provided by the standard libary. Remove those definitions and the program will compile OK.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie!
George
|
|
|
|
|
Hi, everyone!
Here is a sample of the usage of iterator of STL.
When compiling it with VC6.0, some error occur.
I have added the source codes and related error
messages below.
Source:
--------
#include <list>
#include <iostream>
using namespace std;
int main()
{
list<int> l;
// fill l with 1 2 3 4
l.push_back(1);
l.push_back(2);
l.push_back(3);
l.push_back(4);
copy (reverse_iterator<int*, int, int&, ptrdiff_t> (l.end()),
reverse_iterator<int*, int, int&, ptrdiff_t> (l.begin()),
ostream_iterator<int> (cout, " ") );
return 1;
}
--------
Error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI2\testRI2.cpp(15) : error C2440: 'type cast' : cannot convert from
'class std::list<int,class std::allocator<int> >::iterator' to 'class std::reverse_iterator<int *,int,int &,int,int>'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI2\testRI2.cpp(16) : error C2440: 'type cast' : cannot convert from
'class std::list<int,class std::allocator<int> >::iterator' to 'class std::reverse_iterator<int *,int,int &,int,int>'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.
--------
Thanks in advance,
George
|
|
|
|
|
This is not the way of obtaining a reverse iterator to a container. std::iterator is meant to support developers writing their own reverse iterators, so forget about it if you're in user mode.
Check rbegin and rend to learn how to traverse a container in reverse order.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie!
I have tried your method, it works OK!
George
|
|
|
|
|
Hi, everyone!
Here is a sample of the usage of iterator of STL.
When compiling it with VC6.0, some error occur.
I have added the source codes and related error
messages below.
Source:
--------
#include <list>
#include <iostream>
using namespace std;
int main()
{
list<int> l;
// fill l with 1 2 3 4
reverse_bidirectional_iterator <list<int>::iterator,
list<int>::value_type,
list<int>::reference_type,
list<int>::difference_type> r (l.end());
cout << *r << " ";
r++;
cout << *r << " ";
r--;
cout << *r;
}
--------
Error and warnings:
--------
c:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(12) : error C2039: 'reference_type' : is not a member
of 'list<int,class std::allocator<int> >'
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(12) : error C2065: 'reference_type' : undeclared
identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(13) : error C2955: 'reverse_bidirectional_iterator' :
use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\iterator(56) : see declaration of
'reverse_bidirectional_iterator'
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(13) : error C2514:
'std::reverse_bidirectional_iterator' : class has no constructors
c:\program files\microsoft visual studio\vc98\include\iterator(56) : see declaration of
'reverse_bidirectional_iterator'
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(13) : error C2262: 'r' : cannot be destroyed
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(14) : error C2678: binary '*' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(15) : error C2678: binary '++' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(15) : error C2678: binary '++' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(15) : error C2678: binary '++' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(16) : error C2678: binary '*' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(17) : error C2678: binary '--' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(17) : error C2678: binary '--' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(17) : error C2678: binary '--' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(18) : error C2678: binary '*' : no operator defined
which takes a left-hand operand of type 'class std::reverse_bidirectional_iterator' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\testRI\testRI.cpp(19) : warning C4508: 'main' : function should return a
value; 'void' return type assumed
Error executing cl.exe.
--------
How to resolve the trouble?
Thanks in advance,
George
|
|
|
|
|
Use list<int>::reference instead of list<int>::reference_type .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie!
I have tested your method, it works OK!
But why should I use list<int>::reference instead of
list<int>::reference_type?
George
|
|
|
|
|