|
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
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
Hi, everyone!
Here is my simple STL program, it is a spell-checker.
The program copy every word of text to output
that is not in the dictionary. I have added all the source
codes and error messages below. My IDE is VC6.0.
I put "abc 123 def" in c:\\dict.txt and "123 345" in c:\\words.txt.
The output should be 345, but now the output is 123 345.
Who can tell me where the error is?
Source Codes:
--------
#pragma warning(disable : 4786)
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
template <class bidirectional_iterator, class T>
class nonAssocFinder {
public:
nonAssocFinder(bidirectional_iterator begin,
bidirectional_iterator end) :
_begin(begin), _end(end) {}
bool operator() (const T& word) {
cout << binary_search(_begin, _end, word);
return binary_search(_begin, _end, word); }
private:
bidirectional_iterator _begin;
bidirectional_iterator _end;
};
void main()
{
typedef vector<string> dict_type;
ifstream dictFile("c:\\dict.txt");
ifstream wordsFile("c:\\words.txt");
dict_type dictionary;
copy (istream_iterator<string>(dictFile),
istream_iterator<string>(),
back_inserter(dictionary));
remove_copy_if (
istream_iterator<string>(wordsFile),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"),
nonAssocFinder<dict_type::iterator,
dict_type::value_type>
(dictionary.begin(), dictionary.end()));
}
--------
Thanks in advance,
George
|
|
|
|
|
binary_search assumes the range being searched is ordered. Insert this line before remove_copy_if :
sort(dictionary.begin(),dictionary.end()); and the program will work just fine.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
Hi, everyone!
Here is my simple STL program, it is a spell-checker.
The program copy every word of text to output
that is not in the dictionary. I have added all the source
codes and error messages below. My IDE is VC6.0.
Source Codes:
--------
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <fstream>
using namespace std;
template <class bidirectional_iterator, class T>
class nonAssocFinder {
public:
nonAssocFinder(bidirectional_iterator begin,
bidirectional_iterator end) :
_begin(begin), _end(end) {}
bool operator() (const T& word) {
return binary_search(_begin, _end, word); }
private:
bidirectional_iterator _begin;
bidirectional_iterator _end;
};
void main()
{
typedef vector<string > dict_type;
ifstream dictFile("dict.txt");
ifstream wordsFile("words.txt");
dict_type dictionary;
copy (istream_iterator<string>(dictFile),
istream_iterator<string>(),
back_inserter(dictionary));
remove_copy_if (
istream_iterator<string>(wordsFile),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"),
nonAssocFinder<dict_type::iterator,
dict_type::value_type>
(dictionary.begin(), dictionary.end()));
}
--------
Warning and error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const
*,std::basic_string<char,std::char_traits<char>,std::all
ocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255'
characters in the debug information
C:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> >
*,std::basic_string<char,std::char_traits<char>,std::allocator
<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters
in the debug information
c:\program files\microsoft visual studio\vc98\include\iterator(176) : 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)
c:\program files\microsoft visual studio\vc98\include\iterator(176) : while compiling class-template member function
'void __thiscall std::istream_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
>,char,struct std::char_traits<char> >::_Getval(void)'
--------
How to resolve the trouble?
Thanks in advance,
George
|
|
|
|
|