|
Ummm... You sure the error is where you think it is? Try compiling the following sample (which works fine in VC++ 6.0):
#include <string>
#include <map>
#include <iostream>
struct CReport{};
using namespace std;
map<string,CReport>slips;
int main()
{
string str;
CReport report;
pair<map<string,CReport>::iterator, bool> ret =
slips.insert(map<string,CReport>::value_type(str,report));
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Well, if I comment out
pair<map<string,CReport>::iterator, bool> ret =
slips.insert(map<string,CReport>::value_type(str,report));
I don't see the error messages.
Maybe I should mention that this is part of a fairly complicated thing. It is part of a palm conduit lib which is linked against openssl libraries.
Matthew Fleming
|
|
|
|
|
Joaquín's example builds fine for me with VC.NET 7.0.
I'm not entirely sure, but I think that the compiler is failing to find a suitable 'operator<' for std::string (which is of course normally a typedef for std::basic_string< char >).
I can replicate your error by removing the #include <string> line. Are you sure you haven't actually got '#include <string.h>'?
Examining the preprocessed output (use the C++/Preprocessor/Generate Preprocessed File option) shows that std::string and std::basic_string are defined in the internal header file <xstring> but that the operators are defined in <string>.
Ensure that <string> is included, and you should be fine.
The overload of operator< that takes two basic_string parameters (with matching template arguments) in this implementation is a namespace-scope template function, defined at line 125 of <string>.
--
Mike Dimmick
|
|
|
|
|
Yes, you are right, the problem was a missing include. In this program I have to do some C style string handling, so I had #include <string.h>. I thought I also had #include <string>, but I didn't. Apologies to all for my stupidity, and thank you for your assistance.
Matthew Fleming
|
|
|
|
|
Mike Dimmick wrote:
I can replicate your error by removing the #include line. Are you sure you haven't actually got '#include '?
Yes, you are right, the problem was a missing include. In this program I have to do some C style string handling, so I had #include <string.h>. I thought I also had #include <string>, but I didn't. Apologies to all for my stupidity, and thank you for your assistance.
Matthew Fleming
|
|
|
|
|
Just in case it happens again:
You can see the instantiation stack of what's being compiled after the error message in the 'see reference' lines. This shows the function that VC had selected to instantiate for the previous one. Working back along this stack we see that it was trying to compile std::map< std::string, CReport, std::less< std::string >, std::allocator< blah > >::insert(). In trying to compile that, it needed to instantiate an internal class member std::_Tree< blah > etc. The compiler lists the lines at which it needed to instantiate something else. From this we can see that it needed to locate an operator< to compare two std::strings. From that I deduced that somehow the appropriate operator wasn't being found.
This is a big improvement over VC6, which doesn't tell you _why_ it's trying to locate such a routine.
--
Mike Dimmick
|
|
|
|
|
Netmeisters,
I am trying to do something which should be simple. Using Visual C++ I want to create a map containing an STL string as a key and my own type as a value.
#include <string>
#include
#include <iostream>
using namespace std;
map<string,creport>slips;
Then to add a pair to the map:
string str;
pair<map<string,creport>::iterator, bool> ret =
slips.insert(map<string,creport>::value_type(str,report));
But this produces a host of error messages that I've included below.
Can't figure these out at all.
Any assistance much appreciated.
Matthew Fleming
mgf@mcw.edu
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const std::string &) const'
with
[
_Ty=std::string
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(36) : see reference to class template instantiation 'std::less<_Ty>' being compiled
with
[
_Ty=std::string
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(19) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
with
[
_Kty=std::string,
_Ty=CReport,
_Pr=std::less<std::string>,
_Alloc=std::allocator<std::pair<const std::string,creport="">>,
_Mfl=false
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,creport,std::less<std::string>,std::allocator<std::pair<const std::string,creport="">>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,creport,std::less<std::string>,std::allocator<std::pair<const std::string,creport="">>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(101) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,creport,std::less<std::string>,std::allocator<std::pair<const std::string,creport="">>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(77) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,creport,std::less<std::string>,std::allocator<std::pair<const std::string,creport="">>,false>
]
c:\Palm\dpCold\DpCGenCond.cpp(201) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
with
[
_Kty=std::string,
_Ty=CReport,
_Pr=std::less<std::string>,
_Alloc=std::allocator<std::pair<const std::string,creport="">>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &,const std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer2,_Reference2> &)' : could not deduce template argument for 'const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &,const std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer2,_Reference2> &)' : could not deduce template argument for 'const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &,const std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer2,_Reference2> &)' : could not deduce template argument for 'const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Pointer2,_Reference2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(139) : error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
|
|
|
|
|
What data type is report? I recommend std::pair.
Kuphryn
|
|
|
|
|
Hi, everyone!
Please look at the sample codes below:
Output:
--------
12
2
Null is appended!
0
--------
Source code:
--------
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
char input[] = "12\n3456789\n123456789";
char output [3];
istringstream is (input);
while (is.getline (output, sizeof (output), '\n'))
{
cout << output << endl;
cout << strlen (output) << endl;
if (0 == output [strlen (output)])
{
cout << "Null is appended! " << endl;
}
cout << unsigned int (output [strlen (output)]) << endl;
}
return 1;
}
--------
But when I change "char output [3];" to "char output [0xff];", the output
is OK! Tt is,
--------
12
2
Null is appended!
0
3456789
7
Null is appended!
0
123456789
9
Null is appended!
0
--------
I have made a reference to MSDN and failed to find any answers.
Who can explain the reason?
Thanks in advance,
George
|
|
|
|
|
3 characters isn't enough to hold the longer line, 255 is.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddie!
Can you explain me the internal reason why the
loop only executes one time when the sizeof
buffer is 3?
regards,
George
|
|
|
|
|
This is my guess:
On the second iteration, it needs to place the line containing "3456789" into the buffer you supplied. Since the buffer is too small, it returns false. Thus your loop terminates.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddy!
George
|
|
|
|
|
Hi, i dont have much (actually any) experience using ActiveX controls, Say i want to use one like the WinSock Control, or maybe the MSFlexGrid, on my application, How do i do it?, can someone point me in the right direction?
Thanks!
|
|
|
|
|
There are visual ActiveX controls, and windowless ActiveX controls. I assume you are talking about visual controls.
Once the WTL setup is installed, copy the WTL class wizard (AtlApp60.awx + setup.js) files in the Microsoft Visual Studio \ Common \ MSDev98 \ IDE \ Bin.
Then two new project templates should appear when you create new projects.
Choose ATL/WTL App Wizard. In the wizard pages, be sure to check "ActiveX controls".
Once done, go into the resource tab, open a dialog box, right-click on it and choose "Insert Active Controls". You are done!
Technically speaking, a WTL dialog that intends to support ActiveX controls derives from the CAxDialogImpl base class. Which is what you automatically get by checking the appropriate box in the WTL wizard.
|
|
|
|
|
Thanks for your answer!, if i may bother you with just another question, Say i use the Winsock control, how do it "control it"? what i mean is, how do i programatically set its properties, recive notifications from it, etc??
Thanks for your patience! i have some WTL and W32 API experience, but like i said, cero experience in ActiveX!
|
|
|
|
|
1. import the type-library
2. create a running winsock object instance
3. use it
Code is as follows :
1. insert this line in your precompiled headers :
#import "C:\WINNT\System32\MSWINSCK.OCX"
2. add this code in your .cpp :
MSWinsockLib::IMSWinsockControlPtr wscks(_uuidof(MSWinsockLib::Winsock));
3. use intellisense to call methods as they appear in intellisense
wscks-> (intellisense!) ;)
|
|
|
|
|
Thanks!
|
|
|
|
|
I have an ATL project that have a simple class and interface. It contains one object. I wanted my class to implement another interface (IFunctoid from BizTalk Server 2002), so I right-click on the class (in ClassViewer) and choose Implement Interface... from the menu.
I choose the correct DLL that contains the interface definition, and the C++ code is happily added to the existing code when I choose the interface. All C++ seem fine.
The problem is that the IFunctoid interface don't show up in Oleview when I choose View Typelib (it does when I choose Create Instance). It does not show up in COM+ either (the default interface does, but not the IFunctoid interface).
I noticed that the .idl file does not contain any reference to the IFunctoid interface, and there is no such thing like functoid.idl to include in my project.
There is the code generated by the wizard when I chose Implement Interface (I didn't edit the code yet):
#ifndef __SECURITYFUNCTOID_H_
#define __SECURITYFUNCTOID_H_
#include "resource.h"
#import "C:\Program Files\Microsoft BizTalk Server\XML Tools\CannedFunctoids.dll" raw_interfaces_only, raw_native_types,\
no_namespace, named_guids
class ATL_NO_VTABLE CSecurityFunctoid :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CSecurityFunctoid, &CLSID_SecurityFunctoid>,
public IDispatchImpl<ISecurityFunctoid, &IID_ISecurityFunctoid, &LIBID_SECURITYCALCULATIONLib>,
public IDispatchImpl<IFunctoid, &IID_IFunctoid, &LIBID_BTSCannedFunctoidsLib>
{
public:
CSecurityFunctoid()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_SECURITYFUNCTOID)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CSecurityFunctoid)
COM_INTERFACE_ENTRY(ISecurityFunctoid)
COM_INTERFACE_ENTRY2(IDispatch, ISecurityFunctoid)
COM_INTERFACE_ENTRY(IFunctoid)
END_COM_MAP()
public:
STDMETHOD(get_Version)(LONG * pVersion)
{
if (pVersion == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHOD(get_FunctionsCount)(LONG * plCount)
{
if (plCount == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHOD(GetFunctionDescripter)(LONG lIndex, FUNC_CATEGORY * pFuncCategory,
SCRIPT_CATEGORY * pScriptCategory,
FUNC_TYPE * pFuncType,
BSTR * pbstrName,
BSTR * pbstrTooltip,
LONG * plBitmapID,
LONG * plParmCount,
LONG * pFuncId)
{
if (pFuncCategory == NULL)
return E_POINTER;
if (pScriptCategory == NULL)
return E_POINTER;
if (pFuncType == NULL)
return E_POINTER;
if (pbstrName == NULL)
return E_POINTER;
if (pbstrTooltip == NULL)
return E_POINTER;
if (plBitmapID == NULL)
return E_POINTER;
if (plParmCount == NULL)
return E_POINTER;
if (pFuncId == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHOD(GetFunctionParameter)(LONG funcId,
LONG lParameter,
LONG * plConnectionType)
{
if (plConnectionType == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHOD(GetScriptBuffer)(LONG cFuncId,
LONG lInputParameters,
BSTR * pbstrScriptBuffer)
{
if (pbstrScriptBuffer == NULL)
return E_POINTER;
return E_NOTIMPL;
}
};
#endif //__SECURITYFUNCTOID_H_
|
|
|
|
|
Find .tlb file delete it, and rebuild the project.
Somtimes VS messes up....
Brian
|
|
|
|
|
|
Hi. I know how to convert strings to BSTR, COleVariant, and ect.. but how do you convert them back to regular ansi that the Windows API requires.
Thanks in advance.
Martin.
|
|
|
|
|
Well, refer to the ATL String Conversion Macros[^].
Basically you'd be using one of these: OLE2CA (which will make ole/bstr into ansi const char*), OLE2CW (same, but for unicode), or just OLE2CT (which converts depending on your settings for using ANSI / _UNICODE)
|
|
|
|
|
I want to learn ATL.
But when I want to insert a new ATL object using Menu Insert==>New ATL Object.A error was throwed out as "error Invoking ATL Object Wizard Component" .I can't solve the problem.
And I resetup VC++6.0 ,the error exist yet.
And I resetup the system(win2000) and VC++6.0.The error exist yet.
How can I do?
Don't look at me in that way!
|
|
|
|
|
Why does ostream_iterator not work for the second scoped code block in main below?
In VC6 you get an error something like:
"d:\program files\microsoft visual studio\vc98\include\iterator(203) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'const struct std::pair<int,int>' (or there is no acceptable conversion)"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct MyClass
{
MyClass(int f, int s)
: first(f), second(s) {}
int first;
int second;
};
ostream& operator<<(ostream& stream, const MyClass& m)
{
return stream << "First: " << m.first << ", Second: " << m.second;
}
typedef pair<int, int> MyClassPair;
ostream& operator<<(ostream& stream, const MyClassPair& m)
{
return stream << "First: " << m.first << ", Second: " << m.second;
}
int main(int argc, char* argv[])
{
{
vector<MyClass> coll;
for (int i = 1; i <= 10; i++)
{
MyClass m(i, i);
coll.push_back(m);
}
copy(coll.begin(), coll.end(),
ostream_iterator<MyClass>(cout,"\n"));
}
{
vector<MyClassPair> coll;
for (int i = 1; i <= 10; i++)
{
MyClassPair m(i, i);
coll.push_back(m);
}
copy(coll.begin(), coll.end(),
ostream_iterator<MyClassPair>(cout,"\n"));
}
return 0;
}
Kevin
|
|
|
|
|