Scope/Visibility question

  • Thread starter Thread starter Du Dang
  • Start date Start date
D

Du Dang

Hello everyone!

How do I make an enum and a struct visible in all the classes within my name
space?

currently this is how put it ...

// one file
namespace {
struct {
}

enum{ ... }

class { // this one can access the struct
}
}

// another file with the same namespace
namespace {

class { // this class can't see the struct
}

}

Any help would be great!

Thanks
 
You can create a "utility" class and integrate your struct and enum within
it and make them public.
Then to access them, just use MyClass.myStruct & MyClass.myEnum

José
 
Du Dang said:
How do I make an enum and a struct visible in all the classes within my name
space?

You can't restrict visibility to a namespace.
currently this is how put it ...

// one file
namespace {
struct {
}

enum{ ... }

class { // this one can access the struct
}
}

// another file with the same namespace
namespace {

class { // this class can't see the struct
}

}

Any help would be great!

If the above are all in the same assembly, they should be able to see
each other just fine - but you'll need to tell the second class which
namespace the struct is in, of course.

If you could give a short but complete example of your problem in a way
we could try to compile (and see the error) that would help a lot.
 
Thank you ... I think this would work.


José Joye said:
You can create a "utility" class and integrate your struct and enum within
it and make them public.
Then to access them, just use MyClass.myStruct & MyClass.myEnum

José
 
If the above are all in the same assembly, they should be able to see
each other just fine - but you'll need to tell the second class which
namespace the struct is in, of course.

If you could give a short but complete example of your problem in a way
we could try to compile (and see the error) that would help a lot.

I'll keep in that in mind next time I make a post.

Thanks Jon for replying to my post !!!
 
Du Dang said:
That works .... I also but a statement "using <same namespace>" and now I
can access my struct without the preceeding namespace.

Yes - that's basically telling the compiler of the second class which
namespace the struct is in.
 
They should be visible within the same namespace even if the
namespace spans over several files. Be sure to make the members
of struct "public".
 
Back
Top