views:

793

answers:

4

Hi All,

I am experiencing something weird that I dont quite understand.

I am getting errors like:

framework/CP_STLArrayDefines.h(37): error: identifier "CP_String" is undefined
    typedef std::vector<CP_String, std::allocator<CP_String> >      CP_Strings_Array;
                        ^
framework/CP_STLArrayDefines.h(37): error: identifier "CP_String" is undefined
    typedef std::vector<CP_String, std::allocator<CP_String> >

But if I go look in CP_STLArrayDefines, I am clearly doing:

#include "CP_String.h"

if I go look at CP_String.h and .cpp they seem fine.

They are both in the same directory, etc.

What things should I look for?

Here is CP_STLArrayDefine.h:

#ifndef CP_STLArrayDefines_H
#define CP_STLArrayDefines_H

#ifndef TARGET_OS_LINUX
#   pragma once
#endif

// CPLAT_Framework
#include "CP_Point.h"
#include "CP_String.h"
#include "CP_Types.h"

// Standard Library
#include <vector>

CPLAT_Begin_Namespace_CPLAT

    // typedefs
#if ! TARGET_OS_LINUX
    typedef std::vector`<CP_String, std::allocator<`CP_String>` >`      CP_Strings_Array;
    typedef std::vector`<CP_String, std::allocator<`CP_String>` >`::iterator   CP_Strings_Iterator;
    typedef std::vector`<CP_String, std::allocator<`CP_String>` >`::reverse_iterator CP_Strings_ReverseIterator;
+2  A: 

Does maybe also CP_String.h include CP_STLArrayDefines.h, so that both files try to include each other? With include guards in the header files this could lead to an error like you describe.

sth
No CP_String.h does not include CP_STLArrayDefines.h. Each header quard is right:<br/> #ifndef _H_CP_STLArrayDefines#define _H_CP_STLArrayDefines and #ifndef _H_CP_String#define _H_CP_String
Once again, I'd like to point out that those header guard names are illegal. Names beginning with an underscore and an uppercase letter are reserved for the C++ implementation.
anon
@neil - So the Header guards should be CP_STRING_H? Illegal or not, that would not be the source of my error though, correct?
@indi I don't think in this case the illegal names are the problem, though something else wrong with your header guards may very well be.
anon
@neil - I changed those to be CP_STRING_H and CP_STRINGS_H and STLARRAYDEFINES_H and not. I dont know how to solve this to move on.
@indie Remove the header guards altogether from CP_String.h and try to compile the single file (not the whole project) that is causing the original error message.
anon
I'd also observe that mixed case filenames are a bad idea, and that mixed case header guards are a terrible idea!
anon
+1  A: 

Is CP_String.h properly guarded? I mean, the header multi-inclusion guards, of course.

Could it be, that one of the headers included before CP_String.h has the same symbol used in the guards (that happens, when you're copy-pasting include guards from one header to another).

Paulius Maruška
The guards are right: #ifndef _H_CP_String#define _H_CP_String and #ifndef _H_CP_STLArrayDefines #define _H_CP_STLArrayDefines
+4  A: 

If you are certain that it's not a circular include then remember you can always fall back to that often overlooked technique of using the appropriate compiler switch to just dump out the preprocessed source i.e. have it stop before doing the compilation phase. Search through the output of that and you'll find out why the compiler's complaining as you're now looking at what the compiler sees.

The option is /E in MSVC and -E with gcc.

Troubadour
A: 

I don't have enough information to give you an answer, but I'll make a wild guess as to a possible cause for the errors you are seeing. Is CP_String declared inside a namespace? If so what is it? I see the macro invocation: CPLAT_Begin_Namespace_CPLAT, which I assume does something like using namespace CPLAT; and maybe some standard setup. Perhaps, due to the reorganization you mentioned in your comments, CP_String is no longer in the CPLAT namespace, and so the compiler cannot find it.

A. Levy