Problem with enumerators

M

martinacevedo

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
 
P

Pete Becker

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.
 
M

martini

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...
 
H

hibiki

(e-mail address 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
 
L

Larry I Smith

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
 
M

martini

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
 
P

Pete Becker

martini said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top