Inheritance with Anonmous members

Hello Everyone,

I have a class A from which classes B and C derive. There is an existing anonymous namespace method in class C. Now, the idea is to pull it out to the parent class. here is my question. If I define a namespace [ anonymous ] in A and ddefine this method 'callMePlease' there, would I be able to use it in say, either B or C?.

This is what I have tried. In my A.hxx, if I declare & define the method, I am able to do so. However, if I declare the method in A.hxx and define its body A.cxx, i am getting a linking error when I try to use it in C.cxx

Can someone please help me understand this?. Is there a way to do this?.

Thanks,
Pavan.
Last edited on
anonymous namespace method? I'm not sure what you mean. Can you give an example?
Last edited on
The whole point of defining something in an anonymous namespace, is to restrict its scope to that translation unit.

If you want an entity to be accessible by other translation units (i.e. to have external linkage), then don't put it in an anonymous namespace!
There is a good discussion of unnamed (anonymous) namspaces here:
http://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions
Last edited on
Topic archived. No new replies allowed.