tags:

views:

31

answers:

1

Hi,

I have a C++/CLI class library project in VS2005 that i am having some problems with. I have defined a class called Languages which is a an enum class. which looks like this:

"Language.cpp"
namespace Company
{
    namespace product
    {
        public eunm class Languages : int
        {
            English = 1,
            German = 2,
            //etc for other languages
        };
    }
};

I then have another class that tries to references this which lives in the same namespace:

"Language.cpp"
namespace Company
{
    namespace product
    {
        public class LanguageConsumer
        {
        public:
            LanguageConsumer()
            {
            }
        public:
            Languages DoSomething(Languages input)
        {
            if (input == Languages::English)
            {
                //Do something and return
            }
        };
    }
};

However my project doensn't compile. From what i can figure out the different classes can't see each other even thought they are in the same namespace. I assume that i might need to have header files and #includes for the header files but i just don't know enough about C++/CLI to be sure (i come from C# background with hardly any C experience) and i have tried as many different combinations as i can think of. I'm sure i'm missing something very obvious to anybody who knows what they are doing, but alas i do not.

Thanks in advance.

+1  A: 

C++/CLI still compiles like C++, file files are compiled separately and then linked together. This is different from C# which compiles all the files together. At compile time the files don't know about each other so the code doesn't compile (what is this enum?!). You need to have the enum definition in the same file (compilation unit) as the class.

The simple way to do this is to move the code into the same file. The header file solution is to move the enum definition into a header file and then include it (#include) in the other file. #include inserts the text of another file, giving the same effect.

hfcs101