stupid VC++ 7 error...
-
Hi, Does anyone knows why I get this stupid error when trying to compile this source code http://www.codeproject.com/dialog/selectcomputerdialog.asp with Visual C++ 6.0 it compiles without problems, but with Visual Studio .net (release candidate) I get this error... X| e:\VSNet\Vc7\include\xutility(398) : error C2440: 'return' : cannot convert from 'NETRESOURCE *' to 'std::vector<_Ty,_Ax>::_Tptr ' with [ _Ty=CSelectComputerNetwork::CNETRESOURCE, _Ax=std::allocator ] Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast e:\VSNet\Vc7\include\xutility(397) : while compiling class-template member function 'std::vector<_Ty,_Ax>::_Tptr *std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer2,_Reference2>::operator ->(void) const' with [ _Ty=CSelectComputerNetwork::CNETRESOURCE, _Ax=std::allocator, _Diff=std::vector>::difference_type, _Pointer=std::vector>::_Tptr, _Reference=std::vector>::reference, _Pointer2=std::vector>::_Tptr, _Reference2=std::vector>::reference ] e:\VSNet\Vc7\include\vector(372) : see reference to class template instantiation 'std::_Ptrit<_Ty,_Diff,_Pointer,_Reference,_Pointer2,_Reference2>' being compiled with [ _Ty=std::vector>::value_type, _Diff=std::vector>::difference_type, _Pointer=std::vector>::_Tptr, _Reference=std::vector>::reference, _Pointer2=std::vector
My first guess is someone tried to return an iterator from a function that wants to return a pointer, which VC6 probably would be more likely to let you get away with. As has been said, it is kind of pointless asking these questions if you're not going to post some code. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
(ooop. Did not catch the other Reply before I wrote mine...) Mario M. wrote: but I'm not an STL professional and I cannot fix this error. any help would be appreciated.. A Code sample would be a good start. Include the def. of the collection in use. Peace! -=- James.
-
My first guess is someone tried to return an iterator from a function that wants to return a pointer, which VC6 probably would be more likely to let you get away with. As has been said, it is kind of pointless asking these questions if you're not going to post some code. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
Hi, You can find the complete source code project here http://www.codeproject.com/dialog/selectcomputerdialog.asp Mario
-
Hi, You can find the complete source code project here http://www.codeproject.com/dialog/selectcomputerdialog.asp Mario
I'm not going to reboot into W2000, run .Net ( which I still don't know my way around ), reboot again, redial the internet, when you can just post the offending line of source yourself. To be honest, if it wasn't that much hassle, I would do it gladly, although I still think you should have posted the source that is crashing, but to test under .Net is simply too much hassle for me. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
I have other source codes which uses vector and compiles fine, I think there is something which was changed by MS in this new VC++ release...
Mario M. wrote: I have other source codes which uses vector and compiles fine, I think there is something which was changed by MS in this new VC++ release... I have seen the same thing happen when people moved off of VC++ 6.0's STL code to Dinkumware's STL or STLPort. The reason I suggested is still a possibility. So again, can we get a code snippet (not a code archive) that shows the code around, and including the problem (include things like variable declarations, STL typedefs, etc.) Peace! -=- James.
-
I'm not going to reboot into W2000, run .Net ( which I still don't know my way around ), reboot again, redial the internet, when you can just post the offending line of source yourself. To be honest, if it wasn't that much hassle, I would do it gladly, although I still think you should have posted the source that is crashing, but to test under .Net is simply too much hassle for me. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
The error comes from the first line here... ---- vector vecnrDomains; if (!EnumDomains(NULL, vecnrDomains)) return false; for (vector::const_iterator ci = vecnrDomains.begin(); ci != vecnrDomains.end(); ++ci) vecstrDomains.push_back(ci->GetRemoteName()); ------ I am not the author of these sources, someone else posted it to codeguru.com, and it works fine with VC++ 6. - Mario
-
The error comes from the first line here... ---- vector vecnrDomains; if (!EnumDomains(NULL, vecnrDomains)) return false; for (vector::const_iterator ci = vecnrDomains.begin(); ci != vecnrDomains.end(); ++ci) vecstrDomains.push_back(ci->GetRemoteName()); ------ I am not the author of these sources, someone else posted it to codeguru.com, and it works fine with VC++ 6. - Mario
Mario M. wrote: The error comes from the first line here... ---- vector vecnrDomains; if (!EnumDomains(NULL, vecnrDomains)) return false; for (vector::const_iterator ci = vecnrDomains.begin(); ci != vecnrDomains.end(); ++ci) vecstrDomains.push_back(ci->GetRemoteName()); ------ You mean declaring the vector ? Your <> pairs were lost because you didn't post 'as-is' ( see the check box below as you're typing your post ), but whatever is in the vector: does it have a copy constructor ? Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
Mario M. wrote: The error comes from the first line here... ---- vector vecnrDomains; if (!EnumDomains(NULL, vecnrDomains)) return false; for (vector::const_iterator ci = vecnrDomains.begin(); ci != vecnrDomains.end(); ++ci) vecstrDomains.push_back(ci->GetRemoteName()); ------ You mean declaring the vector ? Your <> pairs were lost because you didn't post 'as-is' ( see the check box below as you're typing your post ), but whatever is in the vector: does it have a copy constructor ? Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
I have modified the post to 'as-is'. And here is the vector class... also you can read again the previous message with 'as-is'... class CSelectComputerNetwork { public: CSelectComputerNetwork(); virtual ~CSelectComputerNetwork(); public: static bool GetDomains(vector >& vecstrDomains); static bool GetServers(const basic_string& strDomain, vector >& vecstrServers); private: //NETRESOURCE structure wrapper used to save text data that freed by WNetEnumClose(_); class CNETRESOURCE { public: CNETRESOURCE(const NETRESOURCE& nr): m_nr(nr) { m_strLocalName = nr.lpLocalName ? nr.lpLocalName : _T(""); m_strRemoteName = nr.lpRemoteName ? nr.lpRemoteName : _T(""); m_strComment = nr.lpComment ? nr.lpComment : _T(""); m_strProvider = nr.lpProvider ? nr.lpProvider : _T(""); m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } CNETRESOURCE(const CNETRESOURCE& rhs): m_nr(rhs.m_nr), m_strLocalName(rhs.m_strLocalName), m_strRemoteName(rhs.m_strRemoteName), m_strComment(rhs.m_strComment), m_strProvider(rhs.m_strProvider) { m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } ~CNETRESOURCE() { delete [] m_nr.lpLocalName; delete [] m_nr.lpRemoteName; delete [] m_nr.lpComment; delete [] m_nr.lpProvider; } public: NETRESOURCE* operator &() {
-
I have modified the post to 'as-is'. And here is the vector class... also you can read again the previous message with 'as-is'... class CSelectComputerNetwork { public: CSelectComputerNetwork(); virtual ~CSelectComputerNetwork(); public: static bool GetDomains(vector >& vecstrDomains); static bool GetServers(const basic_string& strDomain, vector >& vecstrServers); private: //NETRESOURCE structure wrapper used to save text data that freed by WNetEnumClose(_); class CNETRESOURCE { public: CNETRESOURCE(const NETRESOURCE& nr): m_nr(nr) { m_strLocalName = nr.lpLocalName ? nr.lpLocalName : _T(""); m_strRemoteName = nr.lpRemoteName ? nr.lpRemoteName : _T(""); m_strComment = nr.lpComment ? nr.lpComment : _T(""); m_strProvider = nr.lpProvider ? nr.lpProvider : _T(""); m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } CNETRESOURCE(const CNETRESOURCE& rhs): m_nr(rhs.m_nr), m_strLocalName(rhs.m_strLocalName), m_strRemoteName(rhs.m_strRemoteName), m_strComment(rhs.m_strComment), m_strProvider(rhs.m_strProvider) { m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } ~CNETRESOURCE() { delete [] m_nr.lpLocalName; delete [] m_nr.lpRemoteName; delete [] m_nr.lpComment; delete [] m_nr.lpProvider; } public: NETRESOURCE* operator &() {
If it's a vector of CNETRESOURCE, then maybe the problem is absence of operator NETRESOURCE in CNETRESOURCE, but to be honest, I'm guessing because I can't test it. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
If it's a vector of CNETRESOURCE, then maybe the problem is absence of operator NETRESOURCE in CNETRESOURCE, but to be honest, I'm guessing because I can't test it. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
I have modified the post to 'as-is'. And here is the vector class... also you can read again the previous message with 'as-is'... class CSelectComputerNetwork { public: CSelectComputerNetwork(); virtual ~CSelectComputerNetwork(); public: static bool GetDomains(vector >& vecstrDomains); static bool GetServers(const basic_string& strDomain, vector >& vecstrServers); private: //NETRESOURCE structure wrapper used to save text data that freed by WNetEnumClose(_); class CNETRESOURCE { public: CNETRESOURCE(const NETRESOURCE& nr): m_nr(nr) { m_strLocalName = nr.lpLocalName ? nr.lpLocalName : _T(""); m_strRemoteName = nr.lpRemoteName ? nr.lpRemoteName : _T(""); m_strComment = nr.lpComment ? nr.lpComment : _T(""); m_strProvider = nr.lpProvider ? nr.lpProvider : _T(""); m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } CNETRESOURCE(const CNETRESOURCE& rhs): m_nr(rhs.m_nr), m_strLocalName(rhs.m_strLocalName), m_strRemoteName(rhs.m_strRemoteName), m_strComment(rhs.m_strComment), m_strProvider(rhs.m_strProvider) { m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1]; _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str()); m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1]; _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str()); m_nr.lpComment = new TCHAR [m_strComment.size() + 1]; _tcscpy(m_nr.lpComment, m_strComment.c_str()); m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1]; _tcscpy(m_nr.lpProvider, m_strProvider.c_str()); } ~CNETRESOURCE() { delete [] m_nr.lpLocalName; delete [] m_nr.lpRemoteName; delete [] m_nr.lpComment; delete [] m_nr.lpProvider; } public: NETRESOURCE* operator &() {
The two NETRESOURCE operators need to be removed. They will cause all sorts of problems with standard STLs
NETRESOURCE\* operator &() { return &m\_nr; } operator NETRESOURCE() const { return m\_nr; }
Specificall,y the operator & is causing the problems. The & operator is used heavily in standard STL. When STL applies the & operator, it is expecting a reference to the class, not a NETRESOURCE *, thus the problem. Tim Smith Descartes Systems Sciences, Inc.
-
The two NETRESOURCE operators need to be removed. They will cause all sorts of problems with standard STLs
NETRESOURCE\* operator &() { return &m\_nr; } operator NETRESOURCE() const { return m\_nr; }
Specificall,y the operator & is causing the problems. The & operator is used heavily in standard STL. When STL applies the & operator, it is expecting a reference to the class, not a NETRESOURCE *, thus the problem. Tim Smith Descartes Systems Sciences, Inc.
Thanks! :), this removes the error, but now I have to find something to replace the operator, since I get this error... SelectComputerNetwork.cpp(58) : error C2664: 'CSelectComputerNetwork::EnumServers' : cannot convert parameter 1 from 'CSelectComputerNetwork::CNETRESOURCE *' to 'NETRESOURCE *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast - Mario
-
Thanks! :), this removes the error, but now I have to find something to replace the operator, since I get this error... SelectComputerNetwork.cpp(58) : error C2664: 'CSelectComputerNetwork::EnumServers' : cannot convert parameter 1 from 'CSelectComputerNetwork::CNETRESOURCE *' to 'NETRESOURCE *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast - Mario
Just make a new routine to get that resource. IMHO, I don't understand why NETRESOURCE was made private when the operator & provided unrestricted access to the member. I would just make NETRESOURCE public and be done with it. Tim Smith Descartes Systems Sciences, Inc.
-
Just make a new routine to get that resource. IMHO, I don't understand why NETRESOURCE was made private when the operator & provided unrestricted access to the member. I would just make NETRESOURCE public and be done with it. Tim Smith Descartes Systems Sciences, Inc.
-
I will try to make a new routine to get NETRESOURCE, I also made NETRESOURCE & CNETRESOURCE public, but I get the same error... Thanks for your time.