Thread: Not Recognizing Include Statements?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    21

    Question Not Recognizing Include Statements?

    I have a header and body code as follows:
    Code:
    #pragma once
    typedef void * Comparable;
    
    class Sort1
    {
    public:
    	Sort1(void);
        ~Sort1(void);
    private:
    	
    	
    };
    Code:
    #include ".\sort1.h"
    #include "Bag_Ptr.h"
    #include "Card.h"
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    Sort1::Sort1(void)
    {
    	char suits[] = "HSCD";
    	char denom[] = "23456789tJQKA";
    	   // a full deck of cards
    	//creating card objects and placing them in a bag
    	Bag_Ptr CardDeck(52);
    	for (int s=0; s<4; s++) for (int d=0; d<13; d++) CardDeck.Add((Card *) new Card(suits[s],denom[d]));
    	
    	Card * card_array[10];
    	for (int i = 0; i < 10; i++){
    	card_array[0] = (Card *) CardDeck.GetOne();
    	}
    	
    	for (int j = 0; j < 10; j++){
    		cout << j + 1 << ": " << card_array[j]->GetDenomination() << " of " << card_array[j]->GetSuit(); 
    	
    	if (j == 9){
    		cout << "/n";
    	}
    	else {
    		cout << ", ";
    	}
    	}
    }
    
    Sort1::~Sort1(void)
    {
    }
    and its giving weird errors upon compilation like at Sort1::Sort1(void), it gives an error of "'Sort1' is not a class or namespace name" and also gives undeclared identifier for my Bag_Ptr class (the class works because im reusing it from a different program). And it just seems like its not using the include statements or something. Any help is appreciated.

    Thanks
    cram

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    #include ".\sort1.h"

    should the above be:

    #include "sort1.h"

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    no it still gives me the same error, any other suggestions?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well for a start, I would turn off precompiled headers, and remove that stdafx.h

    The compiler simply ignores everything upto stdafx.h when you have precompiled headers

    Besides, you should really be including all your headers after all the standard headers.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    okay thanks for the help, but can you just expand on what precompiled headers are as im not to sure ive heard that before?

    Is it related to the fact im getting errors on each of my classes saying "unexpected end of file while looking for precompiled header directive" and if so how can I fix it?

    thanks
    Last edited by cram; 11-18-2004 at 06:08 PM.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Any header that comes with your compiler is precompiled. If the syntax is:

    #include <filename>

    then filename is probably a precompiled header. There are some precompiled headers, like stdafx.h that my use the double quote syntax, but the majority of those will be user defined header files. I don't use any third party headers, so I don't know whether they use the <> or the double quote syntax, though I suspect most would use the <> syntax. Therefore the sequence of listing header files is usually:

    #include <>
    #include ""

    except if you elect to keep the stdafx.h header file, in which case Salem says you need to list that first.

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    To remove the stdafx.h , if you're using MSVC++6.0, delete the file then go to
    menu "Project"->"Settings"
    Choose the "C/C++" tab
    Click the "Category" dropdown list
    Then choose "Not using precompiled headers"
    If you're using MS VS.NET it almost the same but I don't know the steps by memory.

    After that all precompiled header problems disapear, although compilation lasts longer. But for small tasks like you code you don't need the precompiled headers stuff. Only for big projects.
    Last edited by xErath; 11-18-2004 at 11:54 PM.

  8. #8
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    <> means that the compiler should be able to find the header somewhere in a pre-defined path.
    "" means that the header is in the same directory unless the path is actually specified.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Unable to open include file SDL_audio.h
    By rraj.be in forum C Programming
    Replies: 2
    Last Post: 06-28-2008, 08:04 PM
  3. Header file include order
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 05-17-2006, 03:22 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM