Topic: Namespace qualifiers in arguments in function definitions
Author: jivecat@my-deja.com
Date: 1999/09/17 Raw View
Hi!
I've posted this to both comp.lang.c++.moderated and comp.std.c++
(what's the difference between these groups?). Sorry for the cross-
posting, and I hope the respective moderators don't reject this post
because of it. This question has been bugging me for some time now,
and I turn to the wisdom of the net.
{ The two sets of moderators cooperate and cross posts are acceptable.
The article goes through both systems and may take much more time
to reach the net. -jep/clc++m }
[ comp.std.c++ is limited to issues regarding the C++ standard.
see the FAQ referenced below for details. -sdc/csc++ ]
Consider the following ...
*****
// MyClass.h
namespace MyNamespace {
class CMyClass
{
public:
void DoSomething(CMyClass& myClassParam);
CMyClass& GetMe(void);
}; // CMyClass
} // end of namespace
****
// MyClass.cpp
#include "MyClass.h"
void MyNamespace::CMyClass::DoSomething(CMyClass& myClassParam)
{
} // DoSomething
CMyNamespace::CMyClass& CMyNamespace::CMyClass::GetMe(void)
{
} // GetMe
*****
OK ... here's the question. I understand why I have to precede the
return value type of GetMe() with the CMyNamespace scope resolutor.
But why DON'T I have to do the same with the argument list for
DoSomething()? At least, my compiler (MSVC 6) does not complain if I
go with the above, whereas leaving "CMyNamespace" off the return value
type of GetMe() really annoys it. What I want to know is: is the MS
compiler cutting me some slack by allowing me to leave the CMyNamespace
off the parameter clause of DoSomething()? Or is it legal under even a
strict interpretation of the C++ standard? And, if so, what is the
theory behind it? How does the compiler "know" which namespace the
parameters in the argument list refer to (imagine a case of several
namespaces with several convergent type names).
The other question is regarding style. Should I use the above method
(i.e. the header file declarations wrapped in the namespace, while the
class definitions are explicitly resolved into the namespace
individually)? Or should I wrap the definition file with the namespace
too (i.e. by putting a namespace MyNamespace { } around the class
defintion/implementation)? The former method was recommended to me,
and I like it (it makes some sort of weird sense to me). But whether
it is correct or not?
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]