Re: [Dev-C++] Demystifying namespace
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Maya <Esc...@ne...> - 2003-12-19 01:21:09
|
Ok, see that there are a few misunderstandings here. I know that using
the preprocessor '#define' means kind of "replace", so in my statement
'#define line __LINE__' what I am saying is: the next time I use
'line' what I really mean is '__LINE__', but in my rush to finish the
program I started to treat 'line' as a variable, i.e. std::cout <<
jme::line << std::endl which of course is wrong, that is clear to me now.
I have handed in the program at school, and even though it works, I
still have a lot of questions about 'namespace'. I know what you are
thinking, ask the teachers! that's what my dad tells me too. Well I
have, but the teachers in my high school are too preoccupied with the
Christmas stuff to explain it in way that makes sense to ME and not only
to THEM. I mean. So, any help from you guys will be appreciated.
Please don't be rude if I ask questions that are very simple to you, and
above all, don't take me wrong if I say something that might sound
insulting; it is never my intention to be rude to anyone.
I share my email with my dad; he was really P.O. about some guy wring
obscenities to me. I mean, think about what would you feel if someone
starts using that kind of language with your kids, eh!
Hava a good Ho Ho Ho
This class is part of a program I wanted to hand in at school, but as we
all know
=====================
=== GCC ===
namespace jme {
#define method __PRETTY_FUNCTION__
#define file __FILE__
#define line __LINE__
#define function __func__
enum error_t{
//Generic error codes
msg, //Default message
warning, //Warning
fatal, //Display fatal and exit
.....
};
class Exception{
protected:
error_t error;
std::string File, Method;
size_t Line;
public:
//Setters
void setException( jme::error_t, e // Error code
const std::string&, fn // File name
const std::string&, m // Method
size_t l) // Line
{ error = e; File = fn; Method = m; Line = l; }
};// Exception
} // namespace
=======================================
--- Someprogram.H -----
namespace jme{
class SomepogramEx : virtual public jme::Exception{
public:
SomeprogramEx(error_t ec, const std::string& f,
const std::string& m, size_t l);
};//End of SomeprogramEx
class Someprogram{
std::string* str_example;
public:
Someprogram(){
try{str_example = new std::string;}
catch(std::bad_alloc& x){
// This works!!!!
throw jme::SomeprogramEx(msg, file,
method, line);
// This doesn't ?????
throw jme::SomeprogramEx(jme::msg,
jme::file, jme::method, jme::line);
}
}
}; //Someprogram
} // namespace
ce...@te... wrote:
> Yeah, I understand that perfectly.
> I understood the last maya's question as "passing them (__func__ and
> __line__) to a srting!!!??? What you say passes the value, I wanted to
> pass the variable name*". The answer, is that her code, was intending
> to do just that an std:string variable to which a __func__ or
> __liner__ were to be passed..
> It was like her was thinking that when passing the #defined name for
> them the item passed to her string variables where something like the
> name of the "definition" variable, which has no sense. Hum, in that
> moment I saw that sense of her question clearly, know, I wonder if I
> really understood her question.
>
> And yes, the errors should appear there, but I've noticed mingw has
> some tendency to point the errors related to #defined thing in the
> next lines; and thos related to missing ';' in headers to the begining
> of the source file which includes the header.
>
> Thanks.
>
> P.S. - The high cross-posting comes from her message, I simply clicked
> 'reply all'
>
> *which translated to code, say
> __line__ = "this is the line blah" (sorry if this has no sense, but
> I'd never used this);
> She thinks,
> if #define foo __line__
> std::string yuu = foo; ----> yuu = "__line__" (which makes no sense)
> instead of "this is the line blah".
>
> Lars Hallberg wrote:
>
>> Carlos García del Monte wrote:
>>
>>> For what I see, your code is doing exactly the same, but without
>>> using those #defines
>>
>>
>>
>>
>> The strange thing is that You get the error in the std::cout. You
>> suposed tho get them erlier.
>>
>> #define declare preprosessor constant ('dumb' text string constants)
>> that is global, they shuld not care about scope. They are replaced
>> litary as text. Your code:
>>
>> std::string f = foo::file;
>> size_t l = foo::line;
>>
>> Transforme to:
>>
>> std::string f = foo::__func__;
>> size_t l = foo::__LINE__;
>>
>> or rather, the value of thes 'special' constants at the #define. The
>> compile shuld likely find errors there :-/
>>
>> Maya:s code actuly declare thes constants as 'real' constants in the
>> scoop foo, shuld make all the differens!
>>
>> PS Litle *too* much crosposting this, is it not? DS
>>
>> HTH /LaH
>>
>>>
>>> Maya wrote:
>>>
>>>> I want to replace the word __func__ with the word file, and you are
>>>> telling me to assign the value of __func__ to the std::string
>>>> variable?
>>>
>>>
>>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
FYI
http://www.astro.umd.edu/~marshall/abbrev.html
E-Mail Policy
http://www.vif.com/users/escalante/Email_Policy.html
* You cannot exercise your power to a point of humiliation.
- Jean Chretien
* The media's the most powerful entity on earth. They have the
power to make the innocent guilty and to make the guilty
innocent, and that's power.
- Malcom X
* "Innocent until proven guilty", no... not in Canada!!
|