Inheritance with Anonmous members

May 23, 2014 at 7:02am
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 May 23, 2014 at 7:07am
May 23, 2014 at 8:42am
anonymous namespace method? I'm not sure what you mean. Can you give an example?
Last edited on May 23, 2014 at 8:43am
May 23, 2014 at 10:06am
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!
May 23, 2014 at 6:00pm
There is a good discussion of unnamed (anonymous) namspaces here:
http://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions
Last edited on May 23, 2014 at 6:00pm
Topic archived. No new replies allowed.