VC6 -> VC2003 STL compiler error

Hello, I'm having problems porting STL to VC2003.  If anyone could please 
help me convert this code that compiles fine with VC6 to compile with 
VC2003, I'd be grateful:

class StrBuffer: private std::vector<_TCHAR>
{
    typedef std::vector<_TCHAR> Base;

public:

    LPTSTR operator&()
    {
        return Base::begin();    // <-- compiler error

        // The above line's error is:
        //  error C2440: 'return' : cannot convert from 
'std::vector<_Ty>::iterator *' to 'LPTSTR'
        //   with
        //  [
        //     _Ty=_TCHAR
        // ]
        // Types pointed to are unrelated; conversion requires 
reinterpret_cast, C-style cast or function-style cast
    }
}



Another problem code:

    DWORD d1 = 5;
    DWORD d2 = 10;
    DWORD max = std::_cpp_max(d1, d2);

    // the above line gives:    error C2589: '(' : illegal token on right 
side of '::'
    // error C2059: syntax error : '::'


Thanks much,
David



0
dc2983 (3206)
11/25/2006 3:13:05 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
831 Views

Similar Articles

[PageSpeed] 37

David Ching wrote:

> Hello, I'm having problems porting STL to VC2003.  If anyone could please 
> help me convert this code that compiles fine with VC6 to compile with 
> VC2003, I'd be grateful:
> 
> class StrBuffer: private std::vector<_TCHAR>
> {
>     typedef std::vector<_TCHAR> Base;
> 
> public:
> 
>     LPTSTR operator&()
>     {
>         return Base::begin();    // <-- compiler error
> 
>         // The above line's error is:
>         //  error C2440: 'return' : cannot convert from 
> 'std::vector<_Ty>::iterator *' to 'LPTSTR'
>         //   with
>         //  [
>         //     _Ty=_TCHAR
>         // ]
>         // Types pointed to are unrelated; conversion requires 
> reinterpret_cast, C-style cast or function-style cast
>     }
> }
> 
> 
> 
> Another problem code:
> 
>     DWORD d1 = 5;
>     DWORD d2 = 10;
>     DWORD max = std::_cpp_max(d1, d2);
> 
>     // the above line gives:    error C2589: '(' : illegal token on right 
> side of '::'
>     // error C2059: syntax error : '::'
> 
> 
> Thanks much,
> David
David:

1. Iterators are not necessarily pointers. They just happen to be in VC6.

Try

return &(*Base::begin());

2. The use of _cpp_max was an ugly workaround for the fact that windows 
#defines the symbols min and max.

I think in VC2003 you can/must use std::min and std::max. I always did 
this in VC6 also, by using

#define NOMINMAX

in the stdafx.h, and then defining std::min and std::max for myself 
(defying the standard by adding to the std namespace, but then these 
things should never have been missing in the first place ..).

You probabaly need to define NOMINMAX in VC2003 also. This can cause 
other problems, but in my experience they can be worked around.

David Wilkinson
0
no-reply8010 (1791)
11/25/2006 4:05:32 PM
"David Wilkinson" <no-reply@effisols.com> wrote in message 
news:eN80JuKEHHA.3668@TK2MSFTNGP06.phx.gbl...
> 1. Iterators are not necessarily pointers. They just happen to be in VC6.
>
> Try
>
> return &(*Base::begin());
>
> 2. The use of _cpp_max was an ugly workaround for the fact that windows 
> #defines the symbols min and max.
>
> I think in VC2003 you can/must use std::min and std::max. I always did 
> this in VC6 also, by using
>
> #define NOMINMAX
>
> in the stdafx.h, and then defining std::min and std::max for myself 
> (defying the standard by adding to the std namespace, but then these 
> things should never have been missing in the first place ..).
>
> You probabaly need to define NOMINMAX in VC2003 also. This can cause other 
> problems, but in my experience they can be worked around.
>

Thank you so much, David.  Both of your fixes worked.  I never would have 
figured this out!  I had to #define NOMINMAX in the stdafx.h, before 
including any header files.  :-)

-- David




0
dc2983 (3206)
11/25/2006 4:31:59 PM
"David Wilkinson" <no-reply@effisols.com> wrote in message 
news:eN80JuKEHHA.3668@TK2MSFTNGP06.phx.gbl...
> 1. Iterators are not necessarily pointers. They just happen to be in VC6.
>
> Try
>
> return &(*Base::begin());
>

This compiled in VC2005 but at runtime I got this error box:  "vector 
iterator not dereferencable".  On the advice of others, I changed

    &(*Base::begin()) --> &Base::front()


but I still got the error because front() is undefined when the vector is 
empty.  I fixed this problem by changing calls to reserve() to resize() so 
that the elements are physically allocated.

BTW, this is why I say STL is not intuitive.  When you reserve() something, 
you expect the space is committed so you should be able to access the 
elements.  But no, a call to resize(), which by the name is totally 
unintuitive how it is different than reserve(), is needed.  Anyway, I 
appreciate your expert help, David.

Thanks,
David 


0
dc2983 (3206)
11/27/2006 5:18:45 AM
On Mon, 27 Nov 2006 05:18:45 GMT, "David Ching"
<dc@remove-this.dcsoft.com> wrote:

>    &(*Base::begin()) --> &Base::front()
>
>
>but I still got the error because front() is undefined when the vector is 
>empty.  I fixed this problem by changing calls to reserve() to resize() so 
>that the elements are physically allocated.

David: what about trying something like:

    empty() ? NULL : (&Base::front())

reserve() is associated with the "capacity" of the vector, and I think
that maybe your original design of using capacity and not "size" (so
reserve() instead of resize()) was the better one (better than
changing calls to reserve() to resize()).

>BTW, this is why I say STL is not intuitive.  When you reserve() something, 
>you expect the space is committed so you should be able to access the 
>elements.  But no, a call to resize(), which by the name is totally 
>unintuitive how it is different than reserve(), is needed.

I think about reserve() as an "hint" to the vector class instance,
exspecially if you know that you will add lots of elements to the
vector. With reserve() you pre-allocate room in the vector, and avoid
frequent memory reallocation. If you then insert items using
push_back(), you don't have to think about resizing() the vector.

MrAsm
0
invalid460 (432)
11/28/2006 10:09:02 PM
Reply:

Similar Artilces:

Error sending messages
Hy, when i try to send messages sometimes appear a pop-up error of Microsoft Word reporting "error not specified", anyone know this error depend to? Thanks to all Kentucky In news:1137756757.399961.22680@f14g2000cwb.googlegroups.com, Kentucky <aforino@libero.it> typed: > Hy, when i try to send messages sometimes appear a pop-up error of > Microsoft Word reporting "error not specified", anyone know this error > depend to? > Thanks to all > Kentucky I presume you're using Outlook, with Word as e-mail editor, then? Try posting in microsoft.public...

VALUE Error
I have a large spreedsheet from L2 to BE 1268 The majoority of the cells contain data. It appears that not all the data is NUMERIC as I am getting VALUE errors. I would like a macro that would check all the cells to see which one are NOT numeric so that I could change them to MUNERIC and avoid all the VALUE errors I am getting Going accross from l to be I need 4 different totals( I total col L,M,N,s,t u an other total might total the following col O,P,Q,R etc etc Thanks "pcor" <pcor@discussions.microsoft.com> wrote: > I would like a macro that would check all the cell...

Setup Error HELP ME Please
Dear All, I get error message while installing CRM Server 1.2 beta in our domain. All the pre-requisites seems to be installed properly (Active Directory with SP4, DNS with rev.lookup zone, Exchange 2000 with SP3, IIS, Indexing service, MSMQ, XML, MDAC, .Net framework and SQL Server 2000 with SP3). The installation is creating an OU named Adventure Works Cycle The database on SQL Server named Adventure_Works_Cycle_CRMCRYSTAL Adventure_Works_Cycle_METABASE Adventure_Works_Cycle_MSCRM. Setup is also able to create Default web page in IIS. There are no special characters or ampersand or under...

Outlook 2003 Receive Error
I get this message "some messages you marked for download are no longer available on the server" The message was manually deleted from the mail server to fix other problems, but now I get this message for a message that was marked for download. How can I get rid of this error? Is there a queue of marked messages I can flush? ...

Back end error
Hi, I've designed a databse with any users login to it on daily basis (almost 25 users),the front end is working perfectly with most of the users,but actually few users ,when opening the database they get a message that says :"'Could not use O\:my folder\Customer Support_be.mdb' the file is currently in use"... What kind of problem is it? How can i solve it? ...

550 5.7.1 Error
Hi We run Exchange 2003 on Windows 2003. We have just started getting an NDR when we send to a company in the States. This was working last week for definite, now it isn't. The NDR reports: You do not have permission to send to this recipient. For assistance, contact your system administrator. <Our ExchangeServer#5.7.1 smtp;550 5.7.1 <Recipient email address>... Relaying denied> I have turned on Message Tracking and Diagnostic Logging for the MSExchangeTransport, and when doing so I get the following entries on the App Event Log (This is the order they appear in the log): ...

a question about dlls compatibility between vc7 and vc6
I will develop a program with vc7,but that program should base another dll which is developed by vc6,and I have no that dll's code.and then it's not compatible anymore.How can I do it?thanx ********************************************************************** Sent via Fuzzy Software @ http://www.fuzzysoftware.com/ Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... That all depends upon what these dlls depend upon. If they depend upon MFC, you will have issues as now you link/load two versions of MFC. If your modules depend upon common system...

Error: Unable to Read
I saved a file a few days ago, and now I can't open it-- when I do it comes up with the error "Unable to Read File". Can anyone help? Hi any chance you open the file from a floppy disc? -- Regards Frank Kabel Frankfurt, Germany Pat wrote: > I saved a file a few days ago, and now I can't open it-- > when I do it comes up with the error "Unable to Read > File". Can anyone help? What version of excel are you using? If the sender used xl97 (or greater) and you're using xl95, then ask the sender to save it in xl95 format. If you're both using...

Exiting a Do Loop on error
How do I exit a Do Loop when I get an error? I have a vba macro with a do loop which searches a spreadsheet for the string "liquidat", selects the row, cuts and pastes the row to a different worksheet, then goes back to the original worksheet and searches for the string again. Naturally, when it no longer finds the string, it generates the error "Run-time error '91': Object variable or With block variable not set". I tried "On Error Exit Do" but the compiler didn't like this. I tried an ErrorHandler: Exit Do, but the compiler told me the Exit Do was ou...

how do I remove messages not downloaded from errors tab?
after setting size limit on downloading of emails how do I get rid of the messages not downloaded in the errors tab? ...

VC6
I have a real doosee here. I am writing a application and was adding and subtracting code. And then I noticed that in the left class window, I lost one of my classes and added the same doc class so now I have 2 doc classes and 1 lost class. If I click on one of the doc classes I go to the lost class. When I build the project over there are no error messages. I have tried to go backwards with what I had did but can not find the thing that has caused this. Soooo, my question is there a easier way to fix this problem? Thanks! -- Just Al I found it thanks -- Just Al "Al" wrot...

Receiving posting error message
Hi all, I have a client that is new on GP 10.0 (no sp) about 4 mos. Recently, the PO Receiving posting is giving them this error: "**ERROR: Posting to table POP30390. Restore from backup if possible." It does allow them to post to GL and it allows them to do a PO-Match with their vendor invoice. And it is NOT on every PO Receipt or inventory item. Some PO Receipts are posting without this error in same batch. I ran a checklinks on Purchasing and Inventory series and nothing appeared on the error log report. I checked KB and found no matches on articles. Does anyone k...

Error in sql server query on network.
Hi, We have written an application which uses SQL Server 2005 as its database. The database is located on a server and clients connect to the database server using our application. Here is two small tables in the database: ============================================================= create table tkelasman ( [kelasman] int identity primary key not null, [nam] nvarchar(50), family nvarchar(50), father_nam nvarchar(50), identit_number nvarchar(50), shm nvarchar(50), adr ntext, ) create table tkel...

Unknown Error #5
Task 'Hotmail - Sending' reported error (0x800CCCF4) : 'Unknown Error 0x800CCCF4 Task 'Hotmail: Folder:Inbox Synchronizing headers.' reported error (0x800CCCF4) : 'An unknown error has occurred. Please save any existing work and restart the program' This stopped happening when I separately (1) added a ICMP rule to my firewall and (2) turned off antivirus services running, but only briefly. I have followed all KB instructions without avail. I am running Windows 2000 Pro SP3 and Outlook 2003 (11.5608.5703). Hotmail works fine via Internet Explorer and initially it...

Runtime Error #5
This one has me stumped. When I try to start Money 2005, I get the error message: Runtime Error! Program: ......\msmoney.exe R6025 -- pure virtual function call I've run this thru the KB and the one answer they have (replace your MDAC files and reinstall Money ) doesn't work with my XP SP2 system. I can't open Money, I can't uninstall it, I can't re-install it from the CD. I can't open the sample file. I'm stuck. Any thoughts would be appreciated. Thanks, Bill Evans, GA [To reply directly change twentyone to 21] I'm now getting this error - d...

Customization import
I have 2 versions of crm 4.0 From version A, I have exported all customizations. I them uploaded and imported the customizations into version B. I now have a few anomalies... 1) When creating a workflow query, the Opportunity>Status Reason value has missing values. When i check the customized attribute, the values are correct, but they do no appear in the value list in the workflow query. 2) the Opportunity form was altered to show the Status and Status reason fields. The default form shows, not the customized form. Any ideas? I need to iron these issues out as i will be building CRM...

Safe string functions in VC6
I'm stuck in VC6 because of VCN's lack of MFC support (Browse & Wizards) - but in the interest of forward compatibility I need to start replacing depricated functions, such as strncpy. Is there a way to use the new ISO string functions (e.g. strncpy_s) in the VC6 programming environment? I suggest just using CString... its a beautiful thing, especially if youre using MFC a lot. "AVee" wrote: > I'm stuck in VC6 because of VCN's lack of MFC support (Browse & Wizards) - > but in the interest of forward compatibility I need to start replacing > d...

error code 646
While trying to run the updates I received a message saying "error code 646 Windows Update encountered an unknown error" KB981725, KB980469, and KB976382 will not update anyone have a solution? -- ahdesertflower "Ahdesertflower" escribió: > Al tratar de ejecutar las actualizaciones que he recibido un mensaje que dice "código de error 646 > Windows Update ha encontrado un error desconocido "KB981725, KB980469, KB976382 y > No se actualizará Alguien tiene una solución? > - ahdesertflower> "ahdesertflo...

deleting errors
when i try to delete anything from outlook, it gives me an error message and outlook shuts down, and i have to restart the program afterwards, what can i do to fix this so i can delete my messages without the program shutting down? ...

Error Message #6
Hi All I a getting this error message when trying to back up my exchange 2000 database using veritas 9.0: 'Database or database element is corrupt' Any body got any ideas or fixes? Thanks Phill Have you checked Veritas' website? http://seer.support.veritas.com/docs/265159.htm "Phill Heath" <PhillHeath@discussions.microsoft.com> wrote in message news:AA13EDA5-66A0-4916-9C33-E684A58C727D@microsoft.com... > Hi All > > I a getting this error message when trying to back up my exchange 2000 > database using veritas 9.0: > > 'Database or data...

Control replacement
Hi all, I am using VC6. I have a dialog box in the Resources Editor in which there are several controls, including an Edit Control. Sometimes, during initialisation of the dialog (OnInitDialog), I need to replace the Edit control by another control I create by hand. What I am currently doing is hiding the original Edit, and creating the new control. It works fine, but I loose my tabs order. I'd like to give my new control the same tab position the original one has, so that it automatically gets the focus when the window is launched and all looks fine when the user plays with its...

CRM 4.0 installation error.
During brand new installation of CRM 4.0 on Win2k3 Standard Edition, I get following error during installation phase. "Action Microsoft.com.Setup.Server.InstallConfigDatabaseAction failed. Unable to obtain DNS hostname of Active Directory domain controller with ntdsa object name "CN=NTDS Settings,CN=IOPDB,CN=Server,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=iop,DC=net" when i press Ok..the next error is. "Action Microsoft.Crm.Setup.Server.InstallConfigDatabaseAction failed. Database 'MSCRM_Config" already exists.Choose a different database name&qu...

error message pops up
"This program cannot be closed. If it is being debugged, please resume it or close the debugger firts" In middle of working ...

OleDB Error
I've try reinstalling all versions of MDAC. I still always get an error on CRM installation when selecting SQL Server. It says MDAC is not installed, and MDAC required components keep coming back in the list. Environment is Windows Server 2003 SP1 and SQL Server 2005 Enterprise Edition. ...

Compiling MFC project from command line...
Hi, How do I compile and link MFC activex project from command line in MSVC 6.0 Is there any tool which generates such info... Help ! sandSpiderX If you look in the project settings for your ActiveX project, you will see the command line that is used by the IDE for building the project. You should be able to use that command line directly. "sandSpider" <m74.piscean@gmail.com> wrote in message news:1120655631.691634.137580@o13g2000cwo.googlegroups.com... > Hi, > > How do I compile and link MFC activex project from command line in MSVC > 6.0 > > Is the...