?
Solved

Can't include <algorithm>

Posted on 2002-06-27
20
Medium Priority
?
605 Views
Last Modified: 2013-11-20
I have an MFC Doc/View application. I'm using VC6.0 (SP5)/W2K.

Why after adding the line
#include <algorithm>
I'm getting the following errors?

c:\archivos de programa\microsoft visual studio\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
c:\archivos de programa\microsoft visual studio\vc98\include\new(35) : error C2091: function returns function
c:\archivos de programa\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal parameters
c:\archivos de programa\microsoft visual studio\vc98\include\new(36) : error C2061: syntax error : identifier 'THIS_FILE'
c:\archivos de programa\microsoft visual studio\vc98\include\new(37) : error C2091: function returns function
c:\archivos de programa\microsoft visual studio\vc98\include\new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__c
decl operator new(void))(unsigned int)'
        c:\archivos de programa\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
c:\archivos de programa\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
c:\archivos de programa\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function
c:\archivos de programa\microsoft visual studio\vc98\include\memory(17) : error C2784: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' : could not deduce template argument for 'void *(__cde
cl *)(unsigned int,class std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)'
c:\archivos de programa\microsoft visual studio\vc98\include\memory(17) : error C2785: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' and 'void *(__cdecl *__cdecl operator new(void))(unsig
ned int)' have different return types
        c:\archivos de programa\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'
c:\archivos de programa\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
c:\archivos de programa\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest





 
0
Comment
Question by:elito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 5
  • +1
20 Comments
 

Author Comment

by:elito
ID: 7113920
The same problem happens with #include <vector>


0
 
LVL 4

Expert Comment

by:mblat
ID: 7114024
Make sure you are including STL headers before

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

block of code in .cpp files....  Make sure you don't include you headers that have

"include <vector> after that block of code...


Hope it helps..
0
 

Expert Comment

by:nke2000
ID: 7114035
elito,
can you give more info?  what else are you including? in what header are you including this, etc?

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:elito
ID: 7114090
Hi,

This is the code I'm using:

#if !defined(AFX_PREFERENCESSHEET_H__346E3613_CE6D_4AAE_827A_A3A72A586726__INCLUDED_)
#define AFX_PREFERENCESSHEET_H__346E3613_CE6D_4AAE_827A_A3A72A586726__INCLUDED_


#include "Preferences.h"     // Added by ClassView


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PreferencesSheet.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CPreferencesSheet

#include "Page1.h"
#include "Page2.h"
#include "Page3.h"
#include "Page5.h"
#include "Page6.h"     // Added by ClassView
#include "Page7.h"
#include "Page8.h"



#include <vector>


class CPreferencesSheet : public CPropertySheet
{
     DECLARE_DYNAMIC(CPreferencesSheet)

// Construction
public:
     CPreferencesSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
     CPreferencesSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);

// Attributes
public:    
     CPage1          m_Page1;
     CPage2          m_Page2;
     CPage3          m_Page3;
     CPage4          m_Page4;
     CPage5          m_Page5;
     CPage6          m_Page6;
     CPage7          m_Page7;
     CPage8          m_Page8;


// Operations
public:
     CPreferences m_Preferences;
     

// Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CPreferencesSheet)
     public:
     virtual BOOL OnInitDialog();
     //}}AFX_VIRTUAL

// Implementation
public:virtual ~CPreferencesSheet();
     CFont m_NewFont;
     CFont m_ButtonFont;
     CPrefPeakPickingPage m_PeakPickingPage;

     // Generated message map functions
protected:
     //{{AFX_MSG(CPreferencesSheet)
          // NOTE - the ClassWizard will add and remove member functions here.
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PREFERENCESSHEET_H__346E3613_CE6D_4AAE_827A_A3A72A586726__INCLUDED_)
0
 
LVL 4

Expert Comment

by:mblat
ID: 7114444
2 elito:

did you read my comment?  That really should be your problem.
0
 

Author Comment

by:elito
ID: 7114581
mblat,

I'm not including any STL header in a cpp file, only in the .h file, as shown in the code above.
0
 
LVL 4

Expert Comment

by:mblat
ID: 7114670
You header file that includes STL header has to be BEFORE

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

also.  Do you do that?
0
 

Expert Comment

by:nke2000
ID: 7114855
I don't see the code mblat is talking about in your header.  

Move it up above #include "preferences.h" and see if that helps.
0
 
LVL 4

Expert Comment

by:mblat
ID: 7115036
2 nke2000
Code I am talking about is in .cpp file.  What I am saying is that all STL headers have to be included BEFORE that.  
Read all posts in this thread and you see where I am mentioning that.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7118596
Errr, excuse me... Including header files in a header file is bad, bad, BAD practice. Use forward declarations whenever possible or make use of the precompiled header file through stdafx.h and include all those files that rarely/never change in there. Once your application has several hundred classes, maybe even thousands, you will notice how much faster compilation will be. This also decreases the chances for getting circular dependencies that cause the compiler to stop compiling the project altogether.
0
 

Author Comment

by:elito
ID: 7122119
mblat,

I'm sorry but I don't really understand your comment. You are saying that I should include the STL headers before this:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


But this code only appears in cpp files, NOT in header files. As I said before, I'm including the STL header files in the header file (see my code snippet above).

Can you please see more specific?
elito
0
 

Expert Comment

by:nke2000
ID: 7122471
Move #include <vector> up above #include "preferences.h" and see if that helps.

I don't agree with fl0yd's thesis that including headers in headers is a "bad, bad, BAD" practice.  Foolishly including headers in headers is a bad practice.  Show me a Windows or STL header that doesn't include another header and I'll show you an anamoly!
0
 
LVL 4

Expert Comment

by:mblat
ID: 7122577
So you header file hould ne include in .cpp BEFORE this blok of code.

in
MyFile.h

.....

#include <algorithm>

.....


in MyFile.cpp

#include "stdafx.h"
#include "MyFile.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

Just a note: you error is typical compilation error when invalid sequence of .h file is used. Microsoft has a TN on the matter called
PRB: Common Problems When Using STL with STD Namespace

it says it applyes to 4.0, but since MS hasn't updated STL library since 4.0 it also applyes to later versions, ( and I run into it with 6.0 also)
0
 

Author Comment

by:elito
ID: 7122628
Yes, I'm including my header file before that block of code in the cpp file.
I'm still don't know how to circunvent this problem.
0
 

Expert Comment

by:nke2000
ID: 7122668
elito,
did you try my suggestion?

--NKE
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7122799
@ nke:
Show me some source that keeps a compiler busy for an hour and I'll show you how to cut down this time to half by applying a few guidelines like the one I suggested. All of a sudden this "thesis" turns into measurable timespans.

@ elito:
Put all of your STL-includes in your stdafx.h-file. Make sure the STL-includes are included BEFORE any other header file is included. The problem you are facing is that MFC #define's the 'new'-operator with its own version for debug reasons [if you compile your code in Relase-Build I'm sure you're having not problem]. This DEBUG_NEW is not compatible with the standard new-operator - which is what STL is using.
0
 

Author Comment

by:elito
ID: 7122968
Well, I have moved the STL- includes to the stdafx.h file and now the program compiles without errors. However, I'm getting a lot of warnings. Most of them are related to xmemory. For example:

:\archivos de programa\microsoft visual studio\vc98\include\xmemory(37) : warning C4100: '_P' : unreferenced formal parameter
        c:\archivos de programa\microsoft visual studio\vc98\include\xmemory(68) : see reference to function template instantiation 'void __cdecl std::_Destroy(unsigned int *)' being compiled

Is this normal? The programs seems to work properly, but I don't know if this could cause any undesired secondary effect.

Thanks for your help.
0
 
LVL 8

Accepted Solution

by:
fl0yd earned 400 total points
ID: 7123033
Generally warnings are just that - they inform the developer about conditions that might not be as he/she intended. They are to be taken seriously and at least checked to see what's causing them but they are certainly different from errors. Once you've checked what the cause of the warning is and think it's not a problem you can instruct the compiler to not issue this specific warning again with
#pragma warning( disable : 4100 )

Here is a piece of code that will issue warnings to show you what their nature is:

int main( int argc, char* argv[] ) {
    int unused_integer;    // warning that this variable is not used
    for( int i = 0; i < 1; ++i );    // warning of an empty statement
    return 0;
}
0
 

Author Comment

by:elito
ID: 7123148
Thanks fl0yd for the help!
0
 

Expert Comment

by:nke2000
ID: 7123235
fl0yd,
I agree, foolishly adding headers causes problems, but including headers in headers prudently is okay.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
The viewer will learn how to dynamically set the form action using jQuery.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question