|
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
|
|
|
|
|
Because list<int>::reference_type is not defined either in VC++ 6.0 or in the standard.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddie!
Please help me with my next question, I
have just posted it.
George
|
|
|
|
|
Hey Im new to STl,
I just want to know whether MFC and STL can be mixed in a project..
I have developed a MFC Dialog application..Now i want to use list Library but im getting undeclared identifier error..I have included <list.h> hfile too.
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Yes, you can mix'em. This error must be due to some missing #include .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Or he might be forgetting the std:: prefix. (i.e. std::vector).
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, everyone!
When using stack in STL, I meet with the following trouble.
Here are the source codes and related error messages. How to
resolve the trouble? My IDE is VC6.0.
Source Codes:
--------
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
using namespace std;
int main()
{
stack<vector<int> > s1;
stack<list<int> > s2;
stack<deque<int> > s3;
s1.push(1); s1.push(5);
cout << s1.top() << endl;
s1.pop();
cout << s1.size() << endl;
s1.empty()? cout << "empty" : cout << "not empty";
return 0;
}
--------
Error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testStack\testStack.cpp(15) : error C2664: 'push' : cannot convert
parameter 1 from 'const int' to 'const class std::vector<int,class std::allocator<int> > &'
Reason: cannot convert from 'const int' to 'const class std::vector<int,class std::allocator<int> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\testStack\testStack.cpp(15) : error C2664: 'push' : cannot convert
parameter 1 from 'const int' to 'const class std::vector<int,class std::allocator<int> > &'
Reason: cannot convert from 'const int' to 'const class std::vector<int,class std::allocator<int> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\testStack\testStack.cpp(16) : error C2679: binary '<<' : no operator
defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int> >' (or there is no
acceptable
conversion)
--------
Thanks in advance,
George
|
|
|
|
|
I presume you want to create stacks contining int s, based on vector , list or deque ??? What you've actually created is a stack of vector s of int s (s1), a stack of list s of int s (s2) and a stack of deque s of int s (s3). To create stack s of int s based on vector s, list s or deque s, use
stack<int, vector<int> > s1;
stack<int, list<int> > s2;
stack<int, deque<int> > s3;
HTH
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Thanks, Stuart buddies!
George
|
|
|
|
|
Hi again,
I'm using attributed C++/ATL to create a COM server - I've come across a little annoyance: if I implement an interface on a coclass, i.e. derive from the interface, voila! its in the typelib. I want to keep a few interfaces to myself - I've tried adding the [hidden] attribute to the interface declarations, but no luck. Any suggestions?
Nick
|
|
|
|
|
second typelib, that you use internaly, lets say with "#import" or just include output file from midl.exe
|
|
|
|
|
Hi all, I'm undertaking a project that will eventually be run as a DCOM server. I anticipate DCOM for Win98/Me will be involved, but right now what I need to know is whether I can create the app as a service with the ATL wizard and run it as a standard EXE on any Win98 box...?
Thanks for any help,
NB
|
|
|
|
|
Nick Blumhardt wrote:
whether I can create the app as a service with the ATL wizard and run it as a standard EXE on any Win98 box...?
Nope, 9x does not have services (at least not like the NT concept of services). The most you can do is have the EXE call RegisterServiceProcess() , that way the process will not be killed when the current user logs out.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Thanks Mike,
Will look into that. Since I posted this message I've decided that I'd definitely have to do some funky conditional compilation so that there was no need to link to StartServiceCtrlDispatcher() etc anyway.
Maybe using the new attributed ATL I can simply switch the [module] parameters... we'll see
Thanks again,
Nick
|
|
|
|
|
Use delete[] when freeing dynamically allocated arrays created like this:
int * p= new int[1024]; and delete for every other use of new . Rule of thumb: use brackets in delete if and only if brackets where used in the corresponding new .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
I can hardly imagine a case where I should use
delete without brackets.
Can you show me an example?
Cheers,
George
|
|
|
|
|
Imagine harder Never used new without brackets ([ and ] )?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín buddies!
If a use new to allocate an object, should I use delete
to remove it?
For example,
--------
SomeType* p = new SomeType()
delete p;
--------
Am I correct?
Thanks in advance,
George
|
|
|
|
|
You are correct.
I think you will benefit a lot from reading some introductory stuff to C++. Marshall Cline's C++ FAQ Lite[^] is an excellent site to start with.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|