http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Who gets higher salary a Java Programmer or a C++ Programmer? - 11 messages,
6 authors
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
* fstream -> FILE* - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/63fbfcaa31046860?hl=en
* Dereferencing a list Structure - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/8c5c4aff6ded0433?hl=en
* Basic .H/.CPP Location Question - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/6056e1d45918a0f9?hl=en
* question about private member - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/a6df0a5b67849ef0?hl=en
* design a tree structure which generates dynamic substrees - 3 messages, 3
authors
http://groups.google.com/group/comp.lang.c++/t/7cc18ea166d7ec1d?hl=en
* Applying a function to all elements of a container - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/6bc4189b1d5e72d6?hl=en
==============================================================================
TOPIC: Who gets higher salary a Java Programmer or a C++ Programmer?
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
==============================================================================
== 1 of 11 ==
Date: Fri, Nov 28 2008 4:53 pm
From: Lew
Mike Schilling wrote:
> Lew wrote:
>> LR wrote:
>>> AFAIK, calling yourself an engineer without the license is illegal
>>> in
>>> many jurisdictions, although, I don't know what the penalty is and
>>> I
>>> really do with to emphasize this, IANAL.
>> One can call oneself a "software engineer" if one wants in the U.S.,
>> thanks to the First Amendment.
>
> It's not quite that simple. One can't falsely call oneself a "medical
> doctor" or "police officer" and, when challenged by legal authority,
> simply point to the Bill of Rights.
Sure, one can. One just cannot engage in acts that require that one
legitimately be a medical doctor or police officer.
I could walk into a bar and tell a girl with a fetish for policemen that I am
a police officer, and I have broken no law.
--
Lew
== 2 of 11 ==
Date: Fri, Nov 28 2008 5:03 pm
From: Arne Vajhøj
Mike Schilling wrote:
> Lew wrote:
>> LR wrote:
>>> AFAIK, calling yourself an engineer without the license is illegal
>>> in
>>> many jurisdictions, although, I don't know what the penalty is and
>>> I
>>> really do with to emphasize this, IANAL.
>> One can call oneself a "software engineer" if one wants in the U.S.,
>> thanks to the First Amendment.
>
> It's not quite that simple. One can't falsely call oneself a "medical
> doctor" or "police officer" and, when challenged by legal authority,
> simply point to the Bill of Rights.
I think that is correct.
But that does not apply to Engineer or Software Engineer.
Claiming to be a Professional Engineer without a license in
the state would not be allowed.
Arne
== 3 of 11 ==
Date: Fri, Nov 28 2008 5:06 pm
From: Arne Vajhøj
Lew wrote:
> Mike Schilling wrote:
>> Lew wrote:
>>> LR wrote:
>>>> AFAIK, calling yourself an engineer without the license is illegal in
>>>> many jurisdictions, although, I don't know what the penalty is and I
>>>> really do with to emphasize this, IANAL.
>>> One can call oneself a "software engineer" if one wants in the U.S.,
>>> thanks to the First Amendment.
>>
>> It's not quite that simple. One can't falsely call oneself a "medical
>> doctor" or "police officer" and, when challenged by legal authority,
>> simply point to the Bill of Rights.
>
> Sure, one can. One just cannot engage in acts that require that one
> legitimately be a medical doctor or police officer.
>
> I could walk into a bar and tell a girl with a fetish for policemen that
> I am a police officer, and I have broken no law.
First, I think that is walking a very thin line if it ends up in court.
Second, it is not particular relevant for the discussion, since
that is about using the title software engineer not to impress girls
(I doubt they will be impressed by that title but ...) but for work.
Arne
== 4 of 11 ==
Date: Fri, Nov 28 2008 5:14 pm
From: Lew
Lew wrote:
>> I could walk into a bar and tell a girl with a fetish for policemen
>> that I am a police officer, and I have broken no law.
Arne Vajhøj wrote:
> First, I think that is walking a very thin line if it ends up in court.
It would only end up in court if one engaged in the activities reserved for
legitimate policemen. To date, impressing girls in bars by lying about your
profession is not illegal, at least not where the U.S. Constitution prevails.
> Second, it is not particular relevant for the discussion, since
> that is about using the title software engineer not to impress girls
> (I doubt they will be impressed by that title but ...) but for work.
That, too, would only end up in court if one engaged in activities that
required that one be a licensed software engineer. It is entirely relevant.
--
Lew
== 5 of 11 ==
Date: Fri, Nov 28 2008 5:18 pm
From: Arne Vajhøj
Lew wrote:
> Lew wrote:
>>> I could walk into a bar and tell a girl with a fetish for policemen
>>> that I am a police officer, and I have broken no law.
>
> Arne Vajhøj wrote:
>> First, I think that is walking a very thin line if it ends up in court.
>
> It would only end up in court if one engaged in the activities reserved
> for legitimate policemen. To date, impressing girls in bars by lying
> about your profession is not illegal, at least not where the U.S.
> Constitution prevails.
>
>> Second, it is not particular relevant for the discussion, since
>> that is about using the title software engineer not to impress girls
>> (I doubt they will be impressed by that title but ...) but for work.
>
> That, too, would only end up in court if one engaged in activities that
> required that one be a licensed software engineer. It is entirely
> relevant.
Not really.
It is not the first amendment that is important here, but the
fact that the state has not made software engineer something
that requires a certificate by state board and has not made
software engineering something that requires a certfied
software engineer.
Arne
== 6 of 11 ==
Date: Fri, Nov 28 2008 5:32 pm
From: "Daniel T."
Tim Roberts <timr@probo.com> wrote:
>
> I don't drive over a bridge blueprint. The blueprint is the design
> document. The bridge is engineered. With software, that
> "hand-crafted" artistry is exactly what I am driving on.
No, the code isn't what you are "driving on," that's my point. You don't
use C++/Java code when you are writing a document in MSWord/OpenOffice.
The code is a design that the compiler/interpreter uses to create the
program that the user ultimately runs. Our construction process is
automated, but that doesn't mean it's non-existent, and it doesn't mean
that something we are doing just before construction starts is part of
the construction itself.
== 7 of 11 ==
Date: Fri, Nov 28 2008 5:52 pm
From: "Arved Sandstrom"
"Tom Anderson" <twic@urchin.earth.li> wrote in message
news:Pine.LNX.4.64.0811261713040.14016@urchin.earth.li...
> On Tue, 25 Nov 2008, LR wrote:
>
>> Tom Anderson wrote:
>>
>>> Still, i call myself a 'software engineer' because it sounds more
>>> high-status than 'programmer', and i go to a lot of parties with lawyers
>>> and academics and the like.
>>
>> IANAL, but since you're calling yourself a "software engineer" might I
>> ask what jurisdiction you do that in?
>
> In the UK.
>
> tom
In Canada I have never encountered any programmer who calls themselves a
software engineer. We're not allowed to.
Over and above my actual degree, I've taken a Certificate in Software
Engineering from DalTech (it used to be Technical University of Nova
Scotia), and this consisted of 6 courses: project management, human
resources mgmt, quality control/assurance/testing, requirements analysis,
design, and maintenance. None of this is covered in a CS degree, and I'm not
saying it should be. However, if people felt strongly enough about having
software engineers in Canada, I'd support a requirement for formal education
in topics like the above. I'd also add software/systems security as a
course.
Way back when I did most of a B.Eng. after finishing my B.Sc, before
realizing I really, really didn't want to be an electrical engineer. Having
said that, it became clear to me that there was nothing in the typical
engineering curriculum that sets a person up to be more of an "engineer"
than someone studying CS or physics or chemistry...what really does it is
the mentored work experience and professional examinations. In fact (at
least in NS) you don't need an engineering degree to become an engineer -
you just need enough years experience doing an engineer's job, and pass the
exams.
My personal feeling about "software engineers" is that if it's a title we
want to have, we should have equivalent standards to other engineers.
Require courses like the ones I mentioned. Make sure - perhaps through the
professional exams - that the aspirant really knows core CS. Have an
engineer-in-training period (in NS it's 4 years) where you are mentored and
observed, and your work experience is assessed.
Is there value to this? I think there is. One of the reasons for having
professional accreditation (the other big one being public safety) is the
assurance of reasonable competency. Right now in software development you
really don't know what you're getting.
Do all software developers need to be engineers (Assuming such schemes were
adopted)? Probably not. In fact I think few would be. A number of IT jobs
could likely be done by technicians, although the technicians themselves
would be accredited (perhaps two year programmes of study) and also have
work experience before being certified. But probably most software
development would continue to be done by individuals who have no
accreditation. The main difference would be that safety-critical software
would require professional software engineers and technicians, and also that
any client could demand that as they saw fit.
I personally don't much care. I just don't like seeing the title used unless
you really are one. And it's not a title that you award to yourself, I'm
afraid.
AHS
== 8 of 11 ==
Date: Fri, Nov 28 2008 5:57 pm
From: "Daniel T."
Arne Vajhøj <arne@vajhoej.dk> wrote:
> You argue that not fully automated means design.
>
> That is obviously not true.
No, I argue that C++/Java programmers do help design the application.
> Else the brick layer would be designing the building.
The brick layer only has a job because automated tools are more
expensive than him. If it were cheeper to have a human being take
C++/Java code and create machine language/bytecode, we wouldn't be using
automated tools. But I would still say that the builder (i.e., the one
who takes the code that we write and turns it into the program that the
user runs) is not designing, while the person who decides exactly what
the program will do in a given situation is.
What I'm saying is that the decision makers are the designers, it isn't
possible for a non-programmer to make all the decisions a programmer
needs to make, and those decisions are vital for correct code.
We are not mere assembly line workers, no matter how hard corporations
try to put us in that role. The programmers' experience, attitudes and
biases will dramatically affect the design, and eventual effectiveness
of the application.
I'll take another tack... A finished product, whether it's a bridge,
building, or application is complete and not amiable to modification
(except in ways that were specifically designed into it.)
A design for a product is amiable to modification. Parts of the design
can be lifted out and used independently of the product in question.
Beauty can be found in a design, independent of the product that the
design produces. All these aptly describe C++/Java code.
== 9 of 11 ==
Date: Fri, Nov 28 2008 7:04 pm
From: LR
Kai-Uwe Bux wrote:
> LR wrote:
> a) There is some tension about where to put math.
I didn't think so, but this thread has clarified that for me.
> Some place it with the sciences, others don't.
I don't. I tend to think of science as dealing with physical phenomena
and math dealing with, for lack of a better word, abstraction.
I suppose there's some meta-argument about math being a physical
phenomena itself, which might be very interesting and even useful in
some contexts, but maybe not this one.
> All agree that it is somewhat different. On the
> other hand, each science in itself seems to be different from the others.
I'm not sure that I agree with that. All of the sciences are subject to
the same physical laws, aren't they? Even if we don't understand those
laws? Even if the ideas in some of them are somewhat unrealistic and
abstract models themselves? Like say the concept of an electron as a
particle, useful in some contexts, pointless in others? The ideas in
science still have their purpose as a referent to the physical world.
And if they appear to differ, maybe that difference is in the models
that the scientists in each field use, their mental shorthand? But I
certainly believe if a difference between two fields of science
manifested itself as an inconsistency, science as a whole could not
tolerate that situation, it would have to be corrected.
I don't think that math is the same as this.
> b) Looking for physical, chemical, or biological knowledge in programs, you
> will find that there is quite a few programs that incorporate exactly that.
I find that I have a tremendous amount of trouble communicating the
particular idea I am trying to explain here.
I do not debate that people create applications that calculate things
about the physical world.
But I haven't run into an example of them using some law (principle, or
whatever word we'd choose for this concept) of science to create the
software itself, the way an engineer applies physics to build a bridge.
> E.g., the software that NASA uses to guide space probes to other planets
> clearly incorporates a lot of Newtonean mechanics.There are programs to
> compute orbitals for molecules. Those programs embed quantum mechanics to a
> large degree (although most of the program is probably devoted to top-notch
> techniques of number crunching and PDE solving).
Of course there are programs that calculate these things but Newtonian
and quantum mechanics aren't used by software developers to create the
software itself. Or at least I don't know of an instance of that.
> Similarly, much of the software of today is embedded in devices. If you
> drive a modern car, chances are that the anti blocking system for your
> brakes has a computer chip somewhere. The software therein probably
> benefits a lot from physical knowledge about breaking.
Certainly, it will perform calculations about this.
> Any sort of knowledge will find its way into software (e.g., software for
> transactions between banks incorporates much knowledge about the particular
> kinds of transactions involved). Scientific principles are no exception.
I agree that there is software that performs calculations that have to
do with physics and software that performs calculations having to do
with banking. No one claims that the science of banking (not AFAIK a
real term) is used to create the banking software simply because it does
calculations related to banking.
I know that I have a lot of trouble explaining what I mean here exactly,
so if something isn't clear to you, it's almost certainly my fault. If
it isn't clear please let me know and I'll try to clarify.
LR
== 10 of 11 ==
Date: Fri, Nov 28 2008 8:14 pm
From: Keith H Duggar
On Nov 28, 6:59 pm, LR <lr...@superlink.net> wrote:
> Keith H Duggar wrote:
> > Software Engineering is replete with scientific principles.
> > Here are but a few off the top of my head:
>
> I'm not familiar with most of these and I had to look most of them up.
> I'm still in the process of looking some of them up. I am unfortunately
> pressed for time so I regret that I can't give each of these the
> attention they deserve. So briefly, very briefly:
It seems we'll need to wait until you have more time because:
[snip categorizations of the several scientific principles]
> I'm certain that I've overlooked some obvious point or made some
> mistake. Please feel free to point those out.
fails to make any point as far as I can see. Did you have a
point you were trying to make?
> > Murphy's Law
>
> Ok, perhaps you got me. But it's not, I don't think, a scientific law
> or principle. Maybe it should be. Or you haven't offered proof of the
> law, or shown how it's applied to the production of software.
Murphy's Law is applied regularly in engineering disciplines
including software engineering. I do not see much of a need to
"show" this any more than I see a need to show that algebra is
used often in graph theory or combinatorics. That is to say it
is such an obvious fact to anyone with a engineering education
that "showing" it seems trite.
On the other hand, if you are largely (or nearly completely)
ignorant of what engineering involves, how engineering is done,
how engineering is taught, how it relates to science, etc, then
I might be more patience to offer you a bit of free education.
But only if you 1) admit that you are ignorant 2) demonstrate
an open mind and willingness to learn 3) provide an honest
estimate of your current degree of knowledge.
(1) is crucial to establishing the right mindset and attitude.
(2) is obviously necessary in a newsgroup context. (3) is will
help us find an appropriate starting point.
Finally, it would be a kindness and one very helpful to me if
you state honestly what your goal is. Do you seek to learn? Do
you seek to persuade? Do you seek to troll? Do you seek to pass
time? Do you see to reinforce your existing prejudices? Do you
seek to "prove" that you are smart? Do you seek to show that
others are stupid or naive? etc.
KHD
== 11 of 11 ==
Date: Fri, Nov 28 2008 11:20 pm
From: LR
Keith H Duggar wrote:
> On Nov 28, 6:59 pm, LR <lr...@superlink.net> wrote:
>> Keith H Duggar wrote:
>>> Software Engineering is replete with scientific principles.
>>> Here are but a few off the top of my head:
>> I'm not familiar with most of these and I had to look most of them up.
>> I'm still in the process of looking some of them up. I am unfortunately
>> pressed for time so I regret that I can't give each of these the
>> attention they deserve. So briefly, very briefly:
>
> It seems we'll need to wait until you have more time because:
>
> [snip categorizations of the several scientific principles]
>
>> I'm certain that I've overlooked some obvious point or made some
>> mistake. Please feel free to point those out.
>
> fails to make any point as far as I can see. Did you have a
> point you were trying to make?
In the context of this discussion? I'm trying to point out that I don't
think that software development is an engineering discipline and I
suspect it cannot be one.
>
>>> Murphy's Law
>> Ok, perhaps you got me. But it's not, I don't think, a scientific law
>> or principle. Maybe it should be. Or you haven't offered proof of the
>> law, or shown how it's applied to the production of software.
>
> Murphy's Law is applied regularly in engineering disciplines
> including software engineering.
Please be specific. How is it applied in engineering? How does it
qualify as a scientific principle? What physical phenomena is it related to?
> I do not see much of a need to
> "show" this any more than I see a need to show that algebra is
> used often in graph theory or combinatorics. That is to say it
> is such an obvious fact to anyone with a engineering education
> that "showing" it seems trite.
I don't have an engineering education.
> On the other hand, if you are largely (or nearly completely)
> ignorant of what engineering involves, how engineering is done,
> how engineering is taught, how it relates to science, etc, then
> I might be more patience to offer you a bit of free education.
> But only if you 1) admit that you are ignorant
I cheerfully admit that I am ignorant and my ignorance is vast.
> 2) demonstrate an open mind and willingness to learn
Please tell me how this can be demonstrated.
> 3) provide an honest estimate of your current degree of knowledge.
Isn't that redundant? I mean given item 1? And if not, and I am
ignorant, how can I presume to do this?
> (1) is crucial to establishing the right mindset and attitude.
Then it would seem that I completely in the right frame of mind and I
have the proper attitude.
> (2) is obviously necessary in a newsgroup context.
I think this is too narrow. Frankly I find it a requirement in almost
every aspect of my life.
> (3) is will help us find an appropriate starting point.
My personal view is that the beginning is always the best point to start.
> Finally, it would be a kindness and one very helpful to me if
> you state honestly what your goal is.
This implies a level of self-knowledge that my ignorance might not
allow, but I'll try.
> Do you seek to learn?
I think that I am always seeking to learn. Many things. However, I have
to admit that I one of the things that I have learned over the years is
that my mental abilities are not unlimited. Also, I am not the smartest
person I know.
> Do you seek to persuade?
I don't know the answer to this. I think it may be beyond my abilities
to persuade people. Even in situations where people tell me that they
think I'm right, they very often stick to their own
acknowledged-to-be-wrong opinions. So I'm not sure that I can do that,
although I think I would like to be able to.
> Do you seek to troll?
No. At least I don't think so. It seems like a pointless, obnoxious and
boring thing to do. Although, I understand there are people who troll as
a hobby. What gratification they derive from this I cannot say.
However, I do enjoy the occasional tongue in cheek comment.
> Do you seek to pass time?
Always. With as much pleasure and enjoyment as I can manage, either at
work or play. Is it possible not to do this? What would the alternative be?
> Do you see to reinforce your existing prejudices?
Prejudices? Although I take exception to the word "prejudices" it may be
besides the point of the answer, which in this case is: Yes and no.
> Do you seek to "prove" that you are smart?
Is it even possible to do this? Besides which, I said that I don't
think I'm very persuasive.
> Do you seek to show that others are stupid or naive?
I think that this is so obvious that it need not be proved. But I
wouldn't limit it to others, I'd include myself too.
> etc.
I'm not sure what you wanted by etc., but I would appreciate it, if my
answers incline you to make good on your offer, if you would answer the
questions you asked too. I would like to know how you think, so that I
may better understand what you say.
Should my answers not incline you to make good on your offer, then at
least you can have the satisfaction of knowing that you provided an
interesting opportunity for self-exploration, which I found an education
in itself.
LR
==============================================================================
TOPIC: fstream -> FILE*
http://groups.google.com/group/comp.lang.c++/t/63fbfcaa31046860?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Nov 28 2008 5:11 pm
From: "barcaroller"
Is it possible to somehow get a FILE* file pointer from an fstream object?
The reason I'm asking is that I have C++ code that now needs to link to a C
library which requires FILE* file pointers.
== 2 of 2 ==
Date: Fri, Nov 28 2008 11:00 pm
From: Zjargands
barcaroller wrote:
> Is it possible to somehow get a FILE* file pointer from an fstream object?
> The reason I'm asking is that I have C++ code that now needs to link to a C
> library which requires FILE* file pointers.
I don't believe you can. As a class, fstream has no reason to use a
FILE* internally, it can use whatever it wants. It should be trivial to
extract the open file name however, and then reopen the file using the c
library. Make suer you set your put and get pointers for the file to the
same place they are in the fstream.
==============================================================================
TOPIC: Dereferencing a list Structure
http://groups.google.com/group/comp.lang.c++/t/8c5c4aff6ded0433?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Nov 28 2008 5:43 pm
From: mrc2323@cox.net (Mike Copeland)
In the following code, I get a C2679 error that I don't know how to
handle. The error says I don't have a "binary = operator", but I don't
know what that means, nor how to correct it.
I guess the cause of the problem lies with the string within the
struct, but I need the comparison operator for the sort, don't I?
Please advise. TIA
#include <string>
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
struct TIMESTRUCT
{
string time_bib;
bool operator <(const TIMESTRUCT &rhs) const
{
return time_bib < rhs.time_bib;
}
} workTime;
typedef list<TIMESTRUCT> TIMEVEC;
TIMEVEC timeVect;
list<TIMESTRUCT>::iterator timeIter;
int main(int argc, char *argv[])
{
string wsT;
workTime.time_bib = "Sam", timeVect.push_back(workTime);
workTime.time_bib = "Libby", timeVect.push_back(workTime);
workTime.time_bib = "Bob", timeVect.push_back(workTime);
workTime.time_bib = "Carol", timeVect.push_back(workTime);
workTime.time_bib = "Ted", timeVect.push_back(workTime);
workTime.time_bib = "Alice", timeVect.push_back(workTime);
sort(timeVect.begin(), timeVect.end());
for(timeIter = timeVect.begin(); timeIter != timeVect.end();
timeIter++)
{
workTime = timeIter->time_bib; <- C2679 error
}
return;
}
== 2 of 2 ==
Date: Fri, Nov 28 2008 6:47 pm
From: Kai-Uwe Bux
Mike Copeland wrote:
> In the following code, I get a C2679 error that I don't know how to
> handle. The error says I don't have a "binary = operator", but I don't
> know what that means, nor how to correct it.
> I guess the cause of the problem lies with the string within the
> struct, but I need the comparison operator for the sort, don't I?
Well, either a comparison operator, or a specialization of std::less<>, or
you could pass a comparison predicate to sort.
BTW, where is a sort()?
> Please advise. TIA
>
> #include <string>
> #include <iostream>
> #include <list>
> #include <algorithm>
> using namespace std;
>
> struct TIMESTRUCT
> {
> string time_bib;
> bool operator <(const TIMESTRUCT &rhs) const
> {
> return time_bib < rhs.time_bib;
> }
> } workTime;
> typedef list<TIMESTRUCT> TIMEVEC;
> TIMEVEC timeVect;
> list<TIMESTRUCT>::iterator timeIter;
> int main(int argc, char *argv[])
> {
> string wsT;
>
> workTime.time_bib = "Sam", timeVect.push_back(workTime);
> workTime.time_bib = "Libby", timeVect.push_back(workTime);
> workTime.time_bib = "Bob", timeVect.push_back(workTime);
> workTime.time_bib = "Carol", timeVect.push_back(workTime);
> workTime.time_bib = "Ted", timeVect.push_back(workTime);
> workTime.time_bib = "Alice", timeVect.push_back(workTime);
> sort(timeVect.begin(), timeVect.end());
> for(timeIter = timeVect.begin(); timeIter != timeVect.end();
> timeIter++)
> {
> workTime = timeIter->time_bib; <- C2679 error
timeIter->time_bib is of type std::string
workTime is of type TIMESTRUCT
There is no assignment operator that would allow you to assign a string to a
TIMESTRUCT.
Did you mean:
workTime.time_bib = timeIter->time_bib;
> }
> return;
> }
PS.: It is usually good to reserve all upper case names for macros (and some
people include global constants). For typenames, all upper case identifiers
are probably best avoided.
Best
Kai-Uwe Bux
==============================================================================
TOPIC: Basic .H/.CPP Location Question
http://groups.google.com/group/comp.lang.c++/t/6056e1d45918a0f9?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 6:30 pm
From: LR
NvrBst wrote:
> This seems like a very basic question but I can't seem to google the
> answer. Should the .H and .CPP always be in the same directory? Or
> is it safe to put all my ".h" file in a "inc" folder, and all my .cpp
> files in a "src" folder?
You can use separate directories. I know some who do. I think it's a
little unusual.
>
> MSDN says (#include"") "This form instructs the preprocessor to look
> for include files in the same directory of the file that contains the
> #include statement, and then in the directories of any files that
> include (#include) that file.".
I don't exactly follow your question and you might be better off in a ng
specific to your compiler, but, most compilers have flags or settings
for additional include directories that help to specify the search path.
>
> This is just a cosmetic thing, I'm a little new to C++ and wanted to
> know if I'd be laughed out of the room by having seperate "inc" and
> "src" folders,
No, I suspect you might get asked why you want to do it that way. BTW,
why do you want to do things that way? Also, there can be issues with
projects that use multiple libs and have .h files with the same names.
Confusing at least. Sort of a namespace type of thing. People have
various strategies for dealing with those.
Another issue is if you're using an IDE, which may have, so to speak,
it's own ideas, about what files should go in which directories. It can
be pointlessly painful to fight this.
LR
==============================================================================
TOPIC: question about private member
http://groups.google.com/group/comp.lang.c++/t/a6df0a5b67849ef0?hl=en
==============================================================================
== 1 of 5 ==
Date: Fri, Nov 28 2008 6:39 pm
From: "zhangyefei.yefei@gmail.com"
class String
{
public:
String & operate=(const String *other)
{
delete m_data;
m_data=new char[strlen(other.m_data)+1];
strcpy(m_data,other.m_data);
}
private:
char *m_data;
}
in the above calss, why memeber function can access the object other's
private m_data?
according to Principle of Encapsulation ,a boject can not access other
object's private memeber.
do anyone give me any explanation ?
thanks in advance
.
== 2 of 5 ==
Date: Fri, Nov 28 2008 8:26 pm
From: red floyd
zhangyefei.yefei@gmail.com wrote:
I'm assuming you're doing this as a learning exercise, otherwise you
should be using std:;string.
> class String
> {
> public:
> String & operate=(const String *other)
This is incorrect.
String& operator=(const String& other)
> {
> delete m_data;
Undefined behavior.
> m_data=new char[strlen(other.m_data)+1];
> strcpy(m_data,other.m_data);
This is bad with regard to exception safety.
char *tmp = new [strlen(other.m_data) + 1];
strcpy(tmp, other.m_data);
delete[] m_data; // note delete[], not delete
m_data = tmp;
> }
> private:
> char *m_data;
>
> }
>
>
> in the above calss, why memeber function can access the object other's
> private m_data?
> according to Principle of Encapsulation ,a boject can not access other
> object's private memeber.
Because privacy is at the *CLASS* level, not the object level.
Think about it. How would you write a copy constructor or assignment
operator if you couldn't access the private parts of the "other" object?
== 3 of 5 ==
Date: Fri, Nov 28 2008 8:36 pm
From: "Bill"
<zhangyefei.yefei@gmail.com> wrote in message
news:00419a46-05e1-4730-8efc-04aef46477aa@b38g2000prf.googlegroups.com...
> class String
> {
> public:
> String & operate=(const String *other)
> {
> delete m_data;
> m_data=new char[strlen(other.m_data)+1];
> strcpy(m_data,other.m_data);
> }
> private:
> char *m_data;
>
> }
>
>
> in the above calss, why memeber function can access the object other's
> private m_data?
> according to Principle of Encapsulation ,a boject can not access other
> object's private memeber.
>
> do anyone give me any explanation ?
> thanks in advance
> .
>
Because it's a member of the same class. It works this way because it would
be too difficult (or impossible) at compile time to determine which type of
object a pointer in a method was pointing to (IIRC, from Bjarne Stroustrup's
fine book).
Bill
== 4 of 5 ==
Date: Fri, Nov 28 2008 10:54 pm
From: "zhangyefei.yefei@gmail.com"
On Nov 29, 12:26 pm, red floyd <no.spam.h...@example.com> wrote:
> zhangyefei.ye...@gmail.com wrote:
>
> I'm assuming you're doing this as a learning exercise, otherwise you
> should be using std:;string.> class String
> > {
> > public:
> > String & operate=(const String *other)
>
> This is incorrect.
> String& operator=(const String& other)> {
> > delete m_data;
>
> Undefined behavior.
>
> > m_data=new char[strlen(other.m_data)+1];
> > strcpy(m_data,other.m_data);
>
> This is bad with regard to exception safety.
> char *tmp = new [strlen(other.m_data) + 1];
> strcpy(tmp, other.m_data);
> delete[] m_data; // note delete[], not delete
> m_data = tmp;
>
> > }
> > private:
> > char *m_data;
>
> > }
>
> > in the above calss, why memeber function can access the object other's
> > private m_data?
> > according to Principle of Encapsulation ,a boject can not access other
> > object's private memeber.
>
> Because privacy is at the *CLASS* level, not the object level.
> Think about it. How would you write a copy constructor or assignment
> operator if you couldn't access the private parts of the "other" object?
maybe you are right.thank you.
i want to say,how difficult c++ is.
== 5 of 5 ==
Date: Fri, Nov 28 2008 11:18 pm
From: Alan Johnson
zhangyefei.yefei@gmail.com wrote:
> On Nov 29, 12:26 pm, red floyd <no.spam.h...@example.com> wrote:
>> zhangyefei.ye...@gmail.com wrote:
>>
>> I'm assuming you're doing this as a learning exercise, otherwise you
>> should be using std:;string.> class String
>>> {
>>> public:
>>> String & operate=(const String *other)
>> This is incorrect.
>> String& operator=(const String& other)> {
>>> delete m_data;
>> Undefined behavior.
>>
>>> m_data=new char[strlen(other.m_data)+1];
>>> strcpy(m_data,other.m_data);
>> This is bad with regard to exception safety.
>> char *tmp = new [strlen(other.m_data) + 1];
>> strcpy(tmp, other.m_data);
>> delete[] m_data; // note delete[], not delete
>> m_data = tmp;
>>
>>> }
>>> private:
>>> char *m_data;
>>> }
>>> in the above calss, why memeber function can access the object other's
>>> private m_data?
>>> according to Principle of Encapsulation ,a boject can not access other
>>> object's private memeber.
>> Because privacy is at the *CLASS* level, not the object level.
>> Think about it. How would you write a copy constructor or assignment
>> operator if you couldn't access the private parts of the "other" object?
>
> maybe you are right.thank you.
> i want to say,how difficult c++ is.
>
>
While I don't necessarily disagree, this is a strange choice of language
features to use to claim C++ is difficult. That is how private class
members work in pretty much every language I've encountered that
supports the concept.
==============================================================================
TOPIC: design a tree structure which generates dynamic substrees
http://groups.google.com/group/comp.lang.c++/t/7cc18ea166d7ec1d?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Nov 28 2008 8:19 pm
From: dongfei
There is an interview question I am asked in Microsoft. Write a
function to build a word tree from a dictionary ?
Input: a dictionary file
Function: void build(filename);
the sample.
Root--a----t
| |__
|___ bout
by
At first, I design it using a trie tree that every tier contains 26
letters.
struct trienode
{
trienode* subtree[26];
char* ch;
};
But the interviewer said it wastes a lot space. I only need to insert
the nodes if necessary. How to design the data structure to support
the dynamic allocated nodes?
== 2 of 3 ==
Date: Fri, Nov 28 2008 8:27 pm
From: red floyd
dongfei wrote:
> There is an interview question I am asked in Microsoft. Write a
> function to build a word tree from a dictionary ?
>
> Input: a dictionary file
> Function: void build(filename);
> the sample.
> Root--a----t
> | |__
> |___ bout
> by
>
> At first, I design it using a trie tree that every tier contains 26
> letters.
> struct trienode
> {
> trienode* subtree[26];
> char* ch;
> };
>
> But the interviewer said it wastes a lot space. I only need to insert
> the nodes if necessary. How to design the data structure to support
> the dynamic allocated nodes?
You should learn about the associative containers in the Standard Library.
== 3 of 3 ==
Date: Fri, Nov 28 2008 8:52 pm
From: Kai-Uwe Bux
dongfei wrote:
> There is an interview question I am asked in Microsoft. Write a
> function to build a word tree from a dictionary ?
>
> Input: a dictionary file
> Function: void build(filename);
> the sample.
> Root--a----t
> | |__
> |___ bout
> by
>
> At first, I design it using a trie tree that every tier contains 26
> letters.
> struct trienode
> {
> trienode* subtree[26];
> char* ch;
> };
>
> But the interviewer said it wastes a lot space. I only need to insert
> the nodes if necessary. How to design the data structure to support
> the dynamic allocated nodes?
See Knuth: TAOCP, Vol 3, 6.3 (digital searching).
The main idea is a space-time tradeoff. You can do
struct trienode {
char* str;
trienode* next;
trienode* down;
};
and use a linked list for the siblings of a node.
Best
Kai-Uwe Bux
==============================================================================
TOPIC: Applying a function to all elements of a container
http://groups.google.com/group/comp.lang.c++/t/6bc4189b1d5e72d6?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:00 pm
From: r.grimm@science-computing.de
Hallo,
> //A simplistic way of writing Accumulate() would be to iterate through
> all of the members and add the values - is there a more elegant/generic
> way of applying a function to STL container members (I think there is ..
> bind() etc come to mind, but its been a while since I used that part
> ofthe STL... hope some experienced STL users can refresh my memory ..
you can do it in an functional way with boost lambda.
#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>
#include <boost/lambda/lambda.hpp>
int main(){
boost::lambda::placeholder1_type Arg1;
boost::lambda::placeholder2_type Arg2;
std::vector <int> intVec;
for ( unsigned int i=1;i <= 10; ++i) intVec.push_back(i);
std::cout << "mult: " << std::accumulate( intVec.begin(), intVec.end
(),1,Arg1*Arg2) <<"\n";
}
Greetings Rainer
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment