Problem with enumerators

Discussion in 'C++' started by martinacevedo@gmail.com, Apr 23, 2005.

  1. Guest

    I made a library in c++ gcc(3.4) with some classes. Within a classes,
    I have an enumerator type, the problem is when I use the library from
    another c++ project( the library is dynamic linked) I can't use a fully
    qualified name for accessing the enum values. The compiler says that
    the name is not a class or namespace

    ex:
    in the library I have a class like this ..

    ... Test.h
    #include <iostream>
    #include <cstdlib>
    class Test{
    public:
    enum TestEnum{
    valuetest1,
    valuetest2
    };
    TestEnum enumVar;
    Test();

    ~Test();

    };
    and the corresponding cxx

    in client project i have main function
    ... test.cxx
    #include "test.h"
    void main(){
    Test tst;
    Test::TestEnum MyEnumVar ; //this line complie wtihout errors
    tdt.enumVar=Test::TestEnum::valuetest1;//<-- gcc says
    Test::TestEnum is not a class or namespace valuetest1 is not defined at
    this scope




    }

    Any ideas or suggestions
    , Apr 23, 2005
    #1
    1. Advertising

  2. Pete Becker Guest

    wrote:
    > I made a library in c++ gcc(3.4) with some classes. Within a classes,
    > I have an enumerator type, the problem is when I use the library from
    > another c++ project( the library is dynamic linked) I can't use a fully
    > qualified name for accessing the enum values. The compiler says that
    > the name is not a class or namespace
    >


    And the compiler is right: the name is not a class or namespace, so you
    can't use it as part of a qualified name. Just leave it out.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
    Pete Becker, Apr 23, 2005
    #2
    1. Advertising

  3. martini Guest

    thanks, but I stil have a problem , I can modify my own libraries
    moving the enums out of the class, but I use also 3th part
    libraries(like openh323 lib), I need to assign values to variables that
    are enum types. The enumrators are declared within the classes in
    openh323.
    How can I solve this problem without the modification of the source
    code of the openh323.? How can I assign a value using the original name
    of the enum value wtihout casting an integer value?


    Thanks...
    martini, Apr 23, 2005
    #3
  4. hibiki Guest

    a écrit :
    > I made a library in c++ gcc(3.4) with some classes. Within a classes,
    > I have an enumerator type, the problem is when I use the library from
    > another c++ project( the library is dynamic linked) I can't use a fully
    > qualified name for accessing the enum values. The compiler says that
    > the name is not a class or namespace
    >
    > ex:
    > in the library I have a class like this ..
    >
    > .. Test.h
    > #include <iostream>
    > #include <cstdlib>
    > class Test{
    > public:
    > enum TestEnum{
    > valuetest1,
    > valuetest2
    > };
    > TestEnum enumVar;
    > Test();
    >
    > ~Test();
    >
    > };
    > and the corresponding cxx
    >
    > in client project i have main function
    > .. test.cxx
    > #include "test.h"
    > void main(){
    > Test tst;
    > Test::TestEnum MyEnumVar ; //this line complie wtihout errors
    > tdt.enumVar=Test::TestEnum::valuetest1;//<-- gcc says
    > Test::TestEnum is not a class or namespace valuetest1 is not defined at
    > this scope
    >
    >
    >
    >
    > }
    >
    > Any ideas or suggestions
    >


    It is tst.enumVar = Test::valuetest1;
    Because an enumeration is not an object, it's only a type.
    Its contents are not object/variables, they are only values that belong
    to the Test namespace.

    --
    Salutations,

    Joachim Naulet

    06 14 90 06 21
    http://jnaulet.no-ip.com
    hibiki, Apr 23, 2005
    #4
  5. wrote:
    > I made a library in c++ gcc(3.4) with some classes. Within a classes,
    > I have an enumerator type, the problem is when I use the library from
    > another c++ project( the library is dynamic linked) I can't use a fully
    > qualified name for accessing the enum values. The compiler says that
    > the name is not a class or namespace
    >
    > ex:
    > in the library I have a class like this ..
    >
    > .. Test.h
    > #include <iostream>
    > #include <cstdlib>
    > class Test{
    > public:
    > enum TestEnum{
    > valuetest1,
    > valuetest2
    > };
    > TestEnum enumVar;
    > Test();
    >
    > ~Test();
    >
    > };
    > and the corresponding cxx
    >
    > in client project i have main function
    > .. test.cxx
    > #include "test.h"
    > void main(){
    > Test tst;
    > Test::TestEnum MyEnumVar ; //this line complie wtihout errors
    > tdt.enumVar=Test::TestEnum::valuetest1;//<-- gcc says
    > Test::TestEnum is not a class or namespace valuetest1 is not defined at
    > this scope
    >
    >
    >
    >
    > }
    >
    > Any ideas or suggestions
    >


    #include <iostream>
    #include <cstdlib>
    class Test{
    public:
    enum TestEnum{
    valuetest1,
    valuetest2
    };
    TestEnum enumVar;
    Test() {};

    ~Test(){};

    };

    int main(){
    Test tst;
    Test::TestEnum MyEnumVar;
    // tst.enumVar=Test::TestEnum::valuetest1;
    tst.enumVar = Test::valuetest1;

    return 0;
    }

    Regards,
    Larry

    --
    Anti-spam address, change each 'X' to '.' to reply directly.
    Larry I Smith, Apr 23, 2005
    #5
  6. martini Guest

    thanks a lot, it works perfectly. I'm porting some code from Win to
    Linux and "Test::TestEnum::valuetest1;" works fine with MS VC++6.
    Thanks
    martini, Apr 23, 2005
    #6
  7. Pete Becker Guest

    martini wrote:

    > thanks, but I stil have a problem , I can modify my own libraries
    > moving the enums out of the class,


    No need for that. Just don't use the name of the enumerator in the
    qualified name. That's what the error message was telling you.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
    Pete Becker, Apr 23, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Taylor
    Replies:
    6
    Views:
    434
    Victor Bazarov
    Jul 13, 2004
  2. Dave
    Replies:
    1
    Views:
    318
    Ron Natalie
    Nov 9, 2005
  3. Replies:
    5
    Views:
    113
  4. Omran Nazir

    Newbie question: Enumerators

    Omran Nazir, Nov 21, 2009, in forum: Ruby
    Replies:
    4
    Views:
    137
    Omran Nazir
    Nov 22, 2009
  5. Hal Fulton

    Enumerators and generators

    Hal Fulton, Jul 22, 2010, in forum: Ruby
    Replies:
    7
    Views:
    126
    Roger Pack
    Jul 22, 2010
Loading...

Share This Page