header files giving errors

Started by
2 comments, last by Oluseyi 17 years, 5 months ago
Hi, I am having trouble with header files xdebug and xlocale. My sink.cpp file is giving me numerous errors, all related to the two header files, when I try to compile it. My stdafx.h (which compiles fine) looks like this: #if !defined(AFX_STDAFX_H__7082897A_3936_4B21_914E_6B1473BEEA3C__INCLUDED_) #define AFX_STDAFX_H__7082897A_3936_4B21_914E_6B1473BEEA3C__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _ATL_APARTMENT_THREADED #define VC_EXTRALEAN #include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT #include <atlbase.h> extern CComModule _Module; #include <atlcom.h> #include <atlwin.h> #include <atlhost.h> #include <exdisp.h> #include <wininet.h> #endif // !defined(AFX_STDAFX_H__7082897A_3936_4B21_914E_6B1473BEEA3C__INCLUDED) In my sink.cpp file, I am including these: #include "stdafx.h" #include "MainDlg.h" #include "Sink.h" #include <Mshtmdid.h> #include <Afxctl.h> #include "shlwapi.h" Maybe the errors that I am getting are due to the order in which I include the files?????? If I comment out the last three includes in the sink.cpp above, I still get the errors. So, there is something with the "stdafx.h" file. But, when I include "stdafx.h" file in other files, it does fine. The errors bugging me are: Compiling... Sink.cpp c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : error C2365: 'operator new' : redefinition; previous definition was 'function' c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : error C2078: too many initializers c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : error C2143: syntax error : missing ';' before '(' c:\program files\microsoft visual studio 8\vc\include\xdebug(32) : error C2226: syntax error : unexpected type 'size_t' c:\program files\microsoft visual studio 8\vc\include\xdebug(33) : error C2059: syntax error : ')' c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C2365: 'operator new' : redefinition; previous definition was 'function' c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C2078: too many initializers c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C2143: syntax error : missing ';' before '[' c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C3409: empty attribute block is not allowed c:\program files\microsoft visual studio 8\vc\include\xdebug(36) : error C2226: syntax error : unexpected type 'size_t' c:\program files\microsoft visual studio 8\vc\include\xlocale(138) : error C2061: syntax error : identifier 'THIS_FILE' c:\program files\microsoft visual studio 8\vc\include\xlocale(139) : error C2091: function returns function c:\program files\microsoft visual studio 8\vc\include\xlocale(139) : error C2802: static member 'operator new' has no formal parameters c:\program files\microsoft visual studio 8\vc\include\xlocale(139) : error C2333: 'std::locale::facet::operator new' : error in function declaration; skipping function body c:\program files\microsoft visual studio 8\vc\include\xlocale(144) : error C2061: syntax error : identifier 'THIS_FILE' c:\program files\microsoft visual studio 8\vc\include\xlocale(146) : error C2091: function returns function c:\program files\microsoft visual studio 8\vc\include\xlocale(146) : error C2556: 'void *(__cdecl *std::locale::facet::operator new(void))(size_t,const std::_DebugHeapTag_t &,char *,int)' : overloaded function differs only by return type from 'void *(__cdecl *std::locale::facet::operator new(void))(size_t)' c:\program files\microsoft visual studio 8\vc\include\xlocale(138) : see declaration of 'std::locale::facet::operator new' c:\program files\microsoft visual studio 8\vc\include\xlocale(147) : error C2059: syntax error : 'return' c:\program files\microsoft visual studio 8\vc\include\xlocale(147) : error C2238: unexpected token(s) preceding ';' c:\program files\microsoft visual studio 8\vc\include\xlocale(150) : error C2628: 'std::locale::facet' followed by 'void' is illegal (did you forget a ';'?) c:\program files\microsoft visual studio 8\vc\include\xlocale(152) : error C2817: return type for 'operator delete' must be 'void' c:\program files\microsoft visual studio 8\vc\include\xlocale(152) : error C2333: 'std::locale::operator delete' : error in function declaration; skipping function body c:\program files\microsoft visual studio 8\vc\include\xlocale(164) : error C2523: 'std::locale::~facet' : destructor tag mismatch c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C2146: syntax error : missing ')' before identifier '_Initrefs' c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C2146: syntax error : missing ';' before identifier '_Initrefs' c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C2071: 'std::locale::size_t' : illegal storage class c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C2059: syntax error : ')' c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft visual studio 8\vc\include\xlocale(169) : error C2864: 'std::locale::_Initrefs' : only static const integral data members can be initialized within a class and it goes on and on................................... I'm using visual C++ 2005 Express Edition. Any help will be really appreciated.
Advertisement
xdebug and xlocale are implementation files related to the Standard C++ Library, so they can't be flawed or everyone who uses the same version of your compiler and standard library would be having the same problem (it's happened in the past). stdafx.h is generated by Visual Studio when you elect to use precompiled headers, and prepopulated with a number of #include statements for headers frequently required by the sort of project you created. You may add your own headers to the end of the file (before the #endif).

Seeing as the file is bog standard, the problem is not there. However, when using precompiled headers, stdafx.h must be the first file included by every implementation (.cpp) file in your project. We don't know if you did that.

Moving on, xlocale most frequently relates to errors with std::string. Do you use std::string in any of your code? Can you show us where?
Hi Oluseyi,
I can't thank you enough. You have no idea how big of my problem you have solved with great ease. I really appreciate your informative and helpful reply. I was using :

#include <string>
typedef std::basic_string<TCHAR> tstring;
#include <vector>

in my sink.cpp file, where i was getting those errors. I commented the above out and all the one hundred and something errors disappeared.

Thank you very much!
Glad to help.

Let me point out that a typedef for wide-character type already exists, std::wstring. It has to be used with wide-character stream objects std::wcout, std::wcin, std::wcerr, std::wclog, which are of std::wstream-derived type. Similarly, for file I/O, you'll need std::wfstream, std::wifstream and std::wofstream.

If you are writing code for mixed mode usage, where some data is in wide character format and other is ASCII, you'll need mbstowcs and wcstombs, too.

This topic is closed to new replies.

Advertisement