0

I have a class called File that is defined (along with other classes) in the header "dmanager1.h". In the "dmanager1.cpp" file (implementation for the dmanager1.h file), when I list the headers in one order I get an error when trying to compile along with my main.cpp (main.cpp is empty except for the header call and an empty "int main()"...basically I'm just testing the class .h and .cpp files)... If I switch the headers around in the dmanager1.cpp file I get no errors. I don't understand what is happening. The error I'm getting is: error: 'File' does not name a type

I get said error when I have my header's ordered in my "dmanager1.cpp" as follows:

#include "dmanager1.h"
#include <iostream>
#include <cstring>

If I switch the header's around to:

 #include <iostream>
 #include <cstring>
 #include "dmanager1.h"

...I don't get the compilation error. Is the first order getting parsed funny? Any thoughts would be greatly appreciated.

EDIT: Added part of the header in question...

#ifndef _dmanager1_h
#define _dmanager1_h


//--------------------
// Forward References
//--------------------
// Node_L, Node_T, and Sector are defined in File: dmanager1a.h
class Node_L;
class Node_T;
class Sector;



class File
{
        public:
                // Default Constructor
                //File();
                // Constructor: Allowing "name", "size", and/or "permissions" to be set
                // Permissions set to default of 0 == read and write
                File(const char * & name, float size = 0, int permissions = 0) : timestamp(11223333) {};
                // Default Destructor
                ~File();

                //returns an int corresponding to the date modified (mmddyy)
                int get_date_mod(void) const {return timestamp;}

                // Return's current level of permission on the File: 0 = read/write, 1 = read only
                int get_permission(void) const {return permission;}

                // Set's Permission to "level": 0 = read/write, 1 = read only
                int set_permission(int level);

        private:
                // Data members
                char * name;
                float size_OA;

                //function used to update "date modified"
                void update_timestamp(void);

                // Current permission level of the file: 0 = read/write, 1 = read only
                int permission;

                //value modified by update_timestamp() and the value returned by get_date_mod().  Date file last edited.
                int timestamp;

};
MCP
  • 4,436
  • 12
  • 44
  • 53

2 Answers2

3

Most likely your dmanager1.h header needs something that iostream or cstring define.

As a result, it doesn't get parsed correctly, and the compiler doesn't understand the declaration of your File class.

If you post your dmanager1.h file, you'll be able to get a more detailed answer.

houbysoft
  • 32,532
  • 24
  • 103
  • 156
2

Make sure that each of your headers is completely self-sufficient. It needs to #include headers for everything that it uses and not assume that they will be included by something else. Every header should work even if it is the only header that a .c file includes.

I'm betting that your dmanager1.h header is using something from the standard library and you aren't including the header that it needs. Swapping the header appears to fix the problem, but it's only working by coincidence.

One diagnostic test you can do is to create a .c file that contains nothing but the line #include "dmanager1.h". Try to compile it. If the compiler throws an error, it should provide hints as to which additional headers need to be included.

Update: I can compile using the initial portion of the header that you posted using g++ -Wall and I get no errors or warnings at all. Please post a sample that reproduces the problem.

bta
  • 43,959
  • 6
  • 69
  • 99
  • What is the best way to post my code? Directly in the post or should I link to it somewhere? – MCP Jul 11 '12 at 23:14
  • 1
    @MCP- You can use something like pastebin if you need to post long snippets of code. For best results, though, post it here, but narrow the problem down to the smallest compilable program that will demonstrate the error. You should be able to come up with a [SSCCE](http://sscce.org/) that fits easily on this page, and in the process of doing so you may just answer your own question. – bta Jul 11 '12 at 23:16