Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem with enumerators

Reply
Thread Tools

Problem with enumerators

 
 
martinacevedo@gmail.com
Guest
Posts: n/a
 
      04-23-2005
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

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      04-23-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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)
 
Reply With Quote
 
 
 
 
martini
Guest
Posts: n/a
 
      04-23-2005
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...

 
Reply With Quote
 
hibiki
Guest
Posts: n/a
 
      04-23-2005
(E-Mail Removed) 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
 
Reply With Quote
 
Larry I Smith
Guest
Posts: n/a
 
      04-23-2005
(E-Mail Removed) 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.
 
Reply With Quote
 
martini
Guest
Posts: n/a
 
      04-23-2005
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

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      04-23-2005
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enumerators and generators Hal Fulton Ruby 7 07-22-2010 07:29 PM
Newbie question: Enumerators Omran Nazir Ruby 4 11-22-2009 11:30 PM
Question about magic enumerators in > 1.8 dblack@wobblini.net Ruby 5 07-10-2006 04:51 PM
typdef'ing a enum and all its enumerators Dave C++ 1 11-09-2005 12:41 PM
Enumerators, Templates, and Type Safety Matt Taylor C++ 6 07-13-2004 01:16 PM



Advertisments