Thread: MS Visual C++ 6 wont include vector.h in a header file

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    4

    Question MS Visual C++ 6 wont include vector.h in a header file

    Hi, Ive been having some trouble using the vector template in visual c++ 6. Basically when I use the line:

    #include <vector>

    in one of my .cpp files everything works fine and I dont have any problem working with vectors, however I need to create a vector that can be used throughout the class but when I try and include vector.h in my header file I get the following errors:

    c:\program files\microsoft visual studio\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
    c:\program files\microsoft visual studio\vc98\include\new(35) : error C2091: function returns function
    c:\program files\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal parameters
    c:\program files\microsoft visual studio\vc98\include\new(36) : error C2061: syntax error : identifier 'THIS_FILE'
    c:\program files\microsoft visual studio\vc98\include\new(37) : error C2091: function returns function
    c:\program files\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 *__cdecl op
    erator new(void))(unsigned int)'
    c:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
    c:\program files\microsoft visual studio\vc98\include\new(41) : error C2061: syntax error : identifier 'THIS_FILE'
    c:\program files\microsoft visual studio\vc98\include\new(42) : error C2091: function returns function
    c:\program files\microsoft visual studio\vc98\include\new(42) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,void *)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsig
    ned int)'
    c:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
    c:\program files\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parameters
    c:\program files\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifier
    c:\program files\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
    c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function
    c:\program files\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 *(__cdecl *)(u
    nsigned int,class std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)'
    c:\program files\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))(unsigned int
    )' have different return types
    c:\program files\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'
    c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
    c:\program files\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest

    This happens regardless of what other header files are included.

    Any help would be greatly appreciated ;-)

    Daniel Bardsley

  2. #2
    Registered User eam's Avatar
    Join Date
    Oct 2003
    Posts
    53
    Try adding
    Code:
    using namespace std;
    if you haven't.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    do the #include before
    Code:
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    not after and your problem is solved.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    4
    The header file doesnt actually have the "#ifdef _DEBUG... etc" code in it.... Here is the whole header file. I also tried using namespace std before and that didnt help either :-( Cheers Guys...

    Code:
    // InputAlg.h: interface for the CInputAlg class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #if !defined(AFX_INPUTALG_H__19F40F40_05D8_4783_88D2_83399070A188__INCLUDED_)
    #define AFX_INPUTALG_H__19F40F40_05D8_4783_88D2_83399070A188__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #include <vector>
    
    #include "cv.h"
    #include "MatchingPoint.h"
    
    class CInputAlg  
    {
    public:
    	CInputAlg();
    	// CInputAlg( vector<int> * ptrMatches );
    	virtual ~CInputAlg();
    	virtual void showSettings() = 0;
    	virtual void updatePoints() = 0;
    	virtual IplImage * getPreview() = 0;
    		
    	bool isUp2Date();
    	void updated();
    	void outOfDate();
    protected:
    	IplImage * right;
    	IplImage * left;
    	void setRightImage(IplImage * right);
    	void setLeftImage(IplImage * left);
    	bool up2Date;
    };
    
    #endif // !defined(AFX_INPUTALG_H__19F40F40_05D8_4783_88D2_83399070A188__INCLUDED_)
    I also tried moving the #include about but that didnt seem to help either and commenting out the include makes it compile fine... Could the problem still be in another file?

  5. #5
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Do this:
    Code:
    #include <vector>
    using namespace std;
    
    // Other includes and code
    It should work fine then.

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <vector>
    using namespace std;
    
    // Other includes and code
    Bad idea. Headers should never have using directives. If you're having namespace problems, resolve the namespace manually. In other words:
    Code:
    #include <vector>
    
    ...
    
    CInputAlg( std::vector<int> * ptrMatches );
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    4
    Thanks for your replies but neither adding the using namespace std worked and since there are no lines in the header file (yet) that use vectors it is simply including the header file that causes the error.

    Could it be anything to do with files included in other headers / source code?

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Could it be anything to do with files included in other headers / source code?
    It could be a lot of things. Unfortunately, we won't be much help unless we have something that we can compile. Follow these steps:

    1) Remove everything you possibly can from your program
    2) Make sure that the problem still exists
    3) Post the code
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    4

    Smile

    Solved :-)

    Thanks for your help guys - another file which included the header file I posted before (inputAlg.h) did so after:

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

    and so caused the error. By moving all my includes above that line it sorted itself out.

    Thanks again.

    Dan

  10. #10

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM