http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* File Generation - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/a3dc865319cdfb52?hl=en
* gcc compiler - debuging - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/14527df8006fbb29?hl=en
* ===Welcome to comp.lang.c++! Read this first. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/77062705c4334c65?hl=en
* Binary file IO: Converting imported sequences of chars to desired type - 5
messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/690c45c0197f60ef?hl=en
* c++0x pods and constructors - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/5aa5848ff079613f?hl=en
* includes algorithm not working properly on sets of strings - 2 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/0e46582a99756035?hl=en
* is LISP the ultimate prgram language? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/90582c87e16a1cd9?hl=en
* Creating a 2D or 3D array? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/a1a600758faa9100?hl=en
* Different treatment of the NodeType of LinkedList in C++ and Java - 2
messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/f3cf235e1c61e0af?hl=en
* Member initialisation and construction - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/92df4caacc840728?hl=en
* help with namespace/friend error - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/5eded7db20190481?hl=en
* Standard Template Library or C? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4494f3354c2a601f?hl=en
* \(0^◇^0)/Whoelsale 2009Newest Fashion Lady Juciy,Edhardy Coat,Sweater,
Christina Audigier Long Tshirts, LV Boots, Christian Louboutin High heal - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/15fd1a268df98ab1?hl=en
==============================================================================
TOPIC: File Generation
http://groups.google.com/group/comp.lang.c++/t/a3dc865319cdfb52?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 8:46 am
From: Jonathan Lee
On Oct 28, 10:48 am, James Kanze <james.ka...@gmail.com> wrote:
> If your answer had really been a riddle, I
> could understand Jonathan's objection to it, but IMHO it was
> more along the lines of: here's what you should do to find the
> answer. IMHO, an excellent and educational response.
I think you're taking me too literally about the "riddle" thing.
But in any event, I don't think Victor's response was poor in
any way. If I had a question of my own I would appreciate,
rather than begrudge, a response from Victor.
Still, I think that hints are obstacles for some, and obstacles
prevent people from using a resource. You say that "he [the OP]
would have found the error immediately, and in the process,
learned a few other important points". But that isn't
_necessarily_ true. It _might_ be the case that he got a more
direct answer somewhere else, and goes there instead of here.
Maybe that's his loss. But Maybe it's ours: it could be he is
learning about C++, but knows a great deal about hardware and
his insight would benefit users here.
When I couple this with the fact that I suspect he would have
"learned the lesson" either way, I don't get the point of
hinting.
*shrugs*
--Jonathan
==============================================================================
TOPIC: gcc compiler - debuging
http://groups.google.com/group/comp.lang.c++/t/14527df8006fbb29?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 8:51 am
From: Jorgen Grahn
On Mon, 2009-10-26, jacob navia wrote:
> Jorgen Grahn a écrit :
>> On Sun, 2009-10-25, Maxim Yegorushkin wrote:
>>> On 25/10/09 14:51, t wrote:
>>>> Hi
>>>> How to debuge programc in gcc
>>> You need to use a debugger, such as gdb. Google for "gdb tutorial".
>>
>> Well, he doesn't actually need a debugger to debug.
>>
>> Debugging is to me the activity of fixing bugs in general. You can do
>> that by reading the code, inserting printf()s, writing unit tests,
>> running it under strace/valgrind/etc, provoking it in various ways ...
>> or stepping around in a symbolic debugger.
>>
>> Personally I never learned to enjoy that last kind of debugging, not
>> even in C with its usually simpler call chains. (Although naturally I
>> use gdb for post-mortem debugging of core dumps -- I'm not stupid).
>
> You never learned to use a debugger?
I never learned to *enjoy* it, that was what I wrote. But yes, I tend
to get lost quickly, and I make frequent mistakes, like setting
breakpoints in the wrong place.
I don't think this is embarrassing or unusual. Most programmers I
know don't use debuggers that way. Maybe it's more common among
Windows programmers -- I have seen one or two good ones use it a lot.
> If you would have learned, then you would need to do post
> mortem debugging less often...
>
> :-)
I doubt that. I haven't seen people step around in a debugger and
discover crashes they couldn't find more easily by just running the
program (possibly under valgrind or a similar tool).
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
==============================================================================
TOPIC: ===Welcome to comp.lang.c++! Read this first.
http://groups.google.com/group/comp.lang.c++/t/77062705c4334c65?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 9:22 am
From: Shiva
Welcome to comp.lang.c++! Read this first.
This post is intended to give the new reader an introduction to reading
and posting in this newsgroup. We respectfully request that you read
all the way through this post, as it helps make for a more pleasant
and useful group for everyone.
First of all, please keep in mind that comp.lang.c++ is a group for discussion
of general issues of the C++ programming language, as defined by the ANSI/ISO
language standard. If you have a problem that is specific to a particular system
or compiler, you are much more likely to get complete and accurate answers in a
group that specializes in your platform. A listing of some newsgroups is given
at the end of this post.
The FAQ (Frequently Asked Question) list has a wealth of information for
both the new and veteran C++ programmer. No matter what your experience
level, you are encouraged to read the entire list, if only to familiarize
yourself with what answers are available to minimize redundant replies.
The comp.lang.c++ FAQ is available at http://www.parashift.com/c++-faq-lite/
If the FAQ list does not help, then many regular readers of this group
are happy to assist with problems of standard C++. We have only a few
requests that we ask be adhered to, for the benefit of all:
* Please put a short summary in the subject line. Descriptions such as
"HELP!!!!!!" are not helpful, and many regular posters ignore such
requests. A good example is, "Problem with Virtual Functions."
* State the question or the problem clearly and concisely. Describe what
you are trying to do, and the problem you are running into. Include all
relevant error messages.
* Include the smallest, complete and compilable program that exhibits your
problem. As a rule, posters in comp.lang.c++ will not do homework, but will
give helpful hints if you have shown some willingness to try a solution.
* comp.lang.c++ is forum for discussion, and as such some regular posters do
not give E-mail replies. Very often follow-ups to postings have corrections,
so plan on taking part in the discussion if you post a question. If you
do receive e-mail replies, it is considered polite to post a summary.
* Don't post in HTML format. Many readers of this newsgroup don't use
newsreaders which can handle HTML postings.
* If you have to include source code in your post, include the
source in the message body. Don't use attachments. A lot
of contributors to this newsgroup won't even notice the existence
of attachments or won't open them. You try to get any help
you can get, don't you?
Some netiquette topics which frequently crop up on comp.lang.c++ are
also answered in the FAQ.
* Should I post job advertisements and/or resumes on comp.lang.c++?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.10
* What if I really need a job; should I post my resume on comp.lang.c++?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.11
* What should I do to someone who posts something off-topic?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.12
A note on comp.lang.c++ etiquette: Accuracy is valued very highly in this
newsgroup; therefore posts are frequently corrected, sometimes perhaps
too harshly, and often to the annoyance of new posters who consider the
correction trivial. Do not take it personally; the best way to fit in
with comp.lang.c++ is to express gratitude for the correction, move on,
and be more careful next time.
This is a very busy group, so these requests are designed to make it as
pleasant and efficient an experience as possible. We hope it proves
a valuable commodity to you.
A list of some Newsgroups :
Languages and Programming
-------------------------
comp.lang.c The C Programming Language
comp.lang.asm.x86 x86 assembly language programming
comp.programming Non-language specific programming
comp.graphics.algorithms Issues of computer graphics
Operating Systems
-----------------
comp.os.msdos.programmer DOS, BIOS, Memory Models, interrupts,
screen handling, hardware
comp.os.ms-windows.programmer.win32 MS/Windows: Mice, DLLs, hardware
comp.os.os2.programmer.misc OS/2 Programming
comp.sys.mac.programmer.misc Macintosh Programming
comp.unix.programmer General Unix: processes, pipes, POSIX,
curses, sockets
comp.unix.[vendor] Various Unix vendors
Microsoft VC++
-------------
microsoft.public.vc.language VC++ issues
microsoft.public.vc.mfc MFC Issues
microsoft.public.dotnet.languages.vc C++/CLR Issues
microsoft.public.dotnet.framework .Net Framework
Borland C++ Builder
-------------------
borland.public.cppbuilder.language Borland C++ Builder
borland.public.cpp.language
borland.public.cppbuilder
-Shiva
http://www.slack.net/~shiva/welcome.txt
Wed Oct 28 12:30:00 EDT 2009
==============================================================================
TOPIC: Binary file IO: Converting imported sequences of chars to desired type
http://groups.google.com/group/comp.lang.c++/t/690c45c0197f60ef?hl=en
==============================================================================
== 1 of 5 ==
Date: Wed, Oct 28 2009 9:53 am
From: mzdude
On Oct 28, 8:42 am, James Kanze <james.ka...@gmail.com> wrote:
> The main reason to use text is that it's an order of magnitude
> easier to debug. And that's not likely to change.
>
Is that text 8 bit ASCII, 16 bit, wchart_t, MBCS, UNICODE ... :^)
== 2 of 5 ==
Date: Wed, Oct 28 2009 11:14 am
From: Mick
mzdude wrote:
> On Oct 28, 8:42 am, James Kanze <james.ka...@gmail.com> wrote:
>> The main reason to use text is that it's an order of magnitude
>> easier to debug. And that's not likely to change.
>>
> Is that text 8 bit ASCII, 16 bit, wchart_t, MBCS, UNICODE ... :^)
Quill & Parchment.
--
------------
< I'm Karmic >
------------
\
\
___
{~._.~}
( Y )
()~*~()
(_)-(_)
== 3 of 5 ==
Date: Wed, Oct 28 2009 1:38 pm
From: Brian
On Oct 28, 7:42 am, James Kanze <james.ka...@gmail.com> wrote:
> On Oct 26, 9:50 pm, Brian <c...@mailvault.com> wrote:
>
> > On Oct 26, 12:06 pm, James Kanze <james.ka...@gmail.com> wrote:
> > I haven't invested in text or XML marshalling because
> > I think binary formats are going to prevail.
>
> Which binary format? There are quite a few to choose from.
>
I'm only aware of a few of them. I don't know if
it matters much to me which one is selected. It's
more that there's a standard.
> > With the portability edge taken away from text, there won't be
> > much reason to use text.
>
> The main reason to use text is that it's an order of magnitude
> easier to debug. And that's not likely to change.
>
I was thinking that having a standard for binary would
help with debugging. I guess it is a tradeoff between
development costs and bandwidth costs.
Brian Wood
http://webEbenezer.net
== 4 of 5 ==
Date: Wed, Oct 28 2009 2:19 pm
From: Brian
On Oct 28, 3:38 pm, Brian <c...@mailvault.com> wrote:
> On Oct 28, 7:42 am, James Kanze <james.ka...@gmail.com> wrote:
>
> > On Oct 26, 9:50 pm, Brian <c...@mailvault.com> wrote:
> > > With the portability edge taken away from text, there won't be
> > > much reason to use text.
>
> > The main reason to use text is that it's an order of magnitude
> > easier to debug. And that's not likely to change.
>
> I was thinking that having a standard for binary would
> help with debugging. I guess it is a tradeoff between
> development costs and bandwidth costs.
>
Does this perspective seem accurate? Assuming the order
of magnitude is correct, then the question becomes
something like if language A takes 10 times longer to
learn than language B, but once you learn A you can
communicate in 1/3 the time it takes for those using B.
So those who learn how to use A have an advantage over
those who don't.
Brian Wood
== 5 of 5 ==
Date: Wed, Oct 28 2009 2:23 pm
From: Gerhard Fiedler
Rune Allnor wrote:
> Here is a test I wrote in matlab a few years ago, to demonstrate
> the problem (WinXP, 2.4GHz, no idea about disk):
>
> [... Matlab code]
>
> Output:
> ------------------------------------
> Wrote ASCII data in 24.0469 seconds
> Read ASCII data in 42.2031 seconds
> Wrote binary data in 0.10938 seconds
> Read binary data in 0.32813 seconds
> ------------------------------------
>
> Binary writes are 24.0/0.1 = 240x faster than text write.
> Binary reads are 42.2/0.32 = 130x faster than text read.
In Matlab. This doesn't say much if anything about any other program.
Possibly Matlab has a lousy (in terms of speed) text IO.
Re the precision issue: When writing out text, there isn't really a need
to go decimal, too. Hex or octal numbers are also text. Speeds up the
conversion (probably not by much, but still) and provides a way to write
out the exact value that is in memory (and recreate that exact value --
no matter the involved precisions).
Gerhard
==============================================================================
TOPIC: c++0x pods and constructors
http://groups.google.com/group/comp.lang.c++/t/5aa5848ff079613f?hl=en
==============================================================================
== 1 of 3 ==
Date: Wed, Oct 28 2009 11:18 am
From: "dragan"
Can C++0x PODs/aggregates have user-defined constructors and still be
PODs/aggregates? If not, why not? How about conversion operators? And what
is the difference between a POD and an aggregate anyway?
== 2 of 3 ==
Date: Wed, Oct 28 2009 12:02 pm
From: Victor Bazarov
dragan wrote:
> Can C++0x PODs/aggregates have user-defined constructors and still be
> PODs/aggregates?
From [dcl.init.aggr]:
<< 1 An aggregate is an array or a class (Clause 9) with no
user-provided constructors (12.1), no private or
protected non-static data members (Clause 11), no base classes (Clause
10), and no virtual functions (10.3). >>
So, no, once you add a user-defined c-tor, it's not an aggregate.
> If not, why not?
Because that's how it's defined. Ask in 'comp.std.c++' for the
rationale behind that definition.
> How about conversion operators?
You can have conversion operators in an aggregate (according to the
definition), if other conditions are met.
> And what
> is the difference between a POD and an aggregate anyway?
And aggregate is a POD. A POD is not necessarily an aggregate.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
== 3 of 3 ==
Date: Wed, Oct 28 2009 12:59 pm
From: "Johannes Schaub (litb)"
dragan wrote:
> Can C++0x PODs/aggregates have user-defined constructors and still be
> PODs/aggregates? If not, why not? How about conversion operators? And what
> is the difference between a POD and an aggregate anyway?
Aggregates but not PODs, both in C++03 and C++0x:
string foo[10];
struct bar {
string baz;
};
In C++0x, you can use memcpy on trivially copyable types. POD is too strict
a requirement for this - so if you just want to use memcpy on a type for
example, making a type trivially copyable would suffice, in particular:
- has no non-trivial copy constructors (12.8),
— has no non-trivial copy assignment operators (13.5.3, 12.8), and
— has a trivial destructor (12.4).
A trivial class then is a class that is trivially copyable and that has a
trivial default constructor. F is trivial and G is trivially copyable:
struct F { Foo() = default; F(int a):a(a) { } int a; };
struct G { Foo(int a):a(a) { } int a; };
For other things, a class has to be a standard layout class. Thus is true
for "offsetof", to inspect a common initial sequence when two such structs
are in an union, etc. Look up the details in the latest draft at 9/6.
A POD is a class is trivial and a standard layout class and has no members
of non-POD etc... . Actually, i haven't found something in the c++0x
language in 2960 that still requires things to be PODs. Things either seem
to refer to standard layout classes or trivially copyable.
==============================================================================
TOPIC: includes algorithm not working properly on sets of strings
http://groups.google.com/group/comp.lang.c++/t/0e46582a99756035?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Oct 28 2009 11:34 am
From: "suresh.amritapuri"
On Oct 28, 4:53 am, Saeed Amrollahi <amrollahi.sa...@gmail.com> wrote:
> On Oct 28, 11:51 am, "suresh.amritapuri" <suresh.amritap...@gmail.com>
> wrote:
>
>
>
> > Hi,
> > just look at includes algorithm on two sets of strings. Its not
> > working correctly.
>
> > bool areql(string x, string y)
> > {
> > return (x==y); //whatever i write here, i get the same result. != or
> > < or > why???}
>
> > int main()
> > {
> > set<string> coll;
> > set<string> search;
> > coll.insert("13");
> > coll.insert("96");
> > coll.insert("0");
>
> > search.insert("17");
> > search.insert("937");
> > // search.insert(7);
> > // check whether all elements in search are also in coll
> > if (includes (coll.begin(), coll.end(),
> > search.begin(), search.end()),areql) {
> > cout << "all elements of search are also in coll"
> > << endl;
> > }
> > else {
> > cout << "not all elements of search are also in coll"
> > << endl;
> > }
>
> > }- Hide quoted text -
>
> > - Show quoted text -
>
> Hi Suresh
>
> My two cents ...
> If you remove areql function, the program works.
>
> Regards
> -- Saeed Amrollahi
Thanks for the comments. I had noted that it would work without the
predicate. But what I wanted was the predicate thing....
suresh
== 2 of 2 ==
Date: Wed, Oct 28 2009 4:14 pm
From: "suresh.amritapuri"
On Oct 28, 6:03 am, Gert-Jan de Vos <gert-
jan.de....@onsneteindhoven.nl> wrote:
> On Oct 28, 9:51 am, "suresh.amritapuri" <suresh.amritap...@gmail.com>
> wrote:
>
>
>
> > Hi,
> > just look at includes algorithm on two sets of strings. Its not
> > working correctly.
>
> > bool areql(string x, string y)
> > {
> > return (x==y); //whatever i write here, i get the same result. != or
> > < or > why???}
>
> > int main()
> > {
> > set<string> coll;
> > set<string> search;
> > coll.insert("13");
> > coll.insert("96");
> > coll.insert("0");
>
> > search.insert("17");
> > search.insert("937");
> > // search.insert(7);
> > // check whether all elements in search are also in coll
> > if (includes (coll.begin(), coll.end(),
> > search.begin(), search.end()),areql) {
> > cout << "all elements of search are also in coll"
> > << endl;
> > }
> > else {
> > cout << "not all elements of search are also in coll"
> > << endl;
> > }
>
> > }
>
> Read here what includes() does and what the predicate function should
> do:
>
> http://www.cplusplus.com/reference/algorithm/includes
>
> Now try to understand why your program does not produce your expected
> result from includes().
>
> Bonus question: would your program still work with the same elements
> in two vector<string>?
Hi
Thanks for the inputs. I solved my initial problem by adding the
function object into the template parameter. But now I have the new
problem. My actual objective is to find out that two sets of strings
are equal, if one string from one set beings with another string in
the other set. Kindly look at the code below and give your valuable
comments.
#include<string>
#include<algorithm>
#include<set>
#include<list>
#include <vector>
#include <iostream>
#include <boost/algorithm/string/predicate.hpp>
using namespace std;
using namespace boost::algorithm;
struct areql{
bool operator()(string x, string y)
{
return (starts_with(x,y)||starts_with(y,x));
}
};
int main()
{
set<string,areql> coll;
set<string,areql> search;
coll.insert("13");
coll.insert("96");
search.insert("137");
search.insert("967");
// check whether all elements in search are also in coll
if(includes(coll.begin(),coll.end(),search.begin(),search.end()))
{
cout << "all elements of search are also in coll"
<< endl;
}
else {
cout << "not all elements of search are also in coll"
<< endl;
}
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
==============================================================================
TOPIC: is LISP the ultimate prgram language?
http://groups.google.com/group/comp.lang.c++/t/90582c87e16a1cd9?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 12:37 pm
From: Jerry Coffin
In article <macros-20091028120310@ram.dialup.fu-berlin.de>,
ram@zedat.fu-berlin.de says...
[ ... ]
> Indeed, there is a paper claiming that Lisp macros were
> an »inspiration« for C macros:
If you honestly want to know what "inspired" C's macros, take a look
at Macro-8 (an assembler for the PDP-8), or Control Data 160G GASS
(General ASsembly System). E.g. See page 5 of:
http://www.bitsavers.org/pdf/cdc/160/CDC_160G_Brochure_Feb64.pdf
C was designed as a "portable assembly language", and by the early
1970's when it was designed, everybody "knew" that any sort of
assembly language needed to have macros.
--
Later,
Jerry.
==============================================================================
TOPIC: Creating a 2D or 3D array?
http://groups.google.com/group/comp.lang.c++/t/a1a600758faa9100?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Oct 28 2009 12:52 pm
From: "carl"
I need to create either a 2D or 3D array based on the dimension specified by
the user. So far I just split it in two cases depending on the specified
parameter:
// 2D grid
if(NDimensions==2) {
double offset = imageSize[0] / (nodes-1) * 1.0;
// generalize to ND ?.
int id = 0;
for (int i = 0; i < nodes; i++) {
for (int j = 0; j < nodes; j++) {
ControlPointType cp;
VectorType location, deformation;
location[0] = i*offset;
location[1] = j*offset;
deformation.Fill(0);
cp.setDeformation(deformation);
cp.setLocation(location);
cp.setId(id);
m_ControlPoints.push_back(cp);
id++;
}
}
}
// 2D cube
if(NDimensions == 3) {
double x_offset = imageSize[0] / (nodes-1) * 1.0;
double y_offset = imageSize[1] / (nodes-1) * 1.0;
double z_offset = imageSize[2] / (nodes-1) * 1.0;
int id = 0;
for (int i = 0; i < nodes; i++) {
for (int j = 0; j < nodes; j++) {
for (int k = 0; k < nodes; k++) {
ControlPointType cp;
VectorType location, deformation;
location[0] = i*x_offset;
location[1] = j*y_offset;
location[2] = k*z_offset;
deformation.Fill(0);
cp.setDeformation(deformation);
cp.setLocation(location);
cp.setId(id);
m_ControlPoints.push_back(cp);
id++;
}
}
}
}
But is there some more generic way to do this or is it only possible when
splitting the code up like above?
== 2 of 2 ==
Date: Wed, Oct 28 2009 1:44 pm
From: Victor Bazarov
carl wrote:
> I need to create either a 2D or 3D array based on the dimension
> specified by the user. So far I just split it in two cases depending on
> the specified parameter:
> [..]
> But is there some more generic way to do this or is it only possible
> when splitting the code up like above?
You seem to have forgotten to mention that the sizes of your dimensions
are the same. Are they? If so, you could write a template, something
in line with
#include <vector>
template<int N, unsigned Exp> struct Pow {
static unsigned long const res = N * Pow<N,Exp-1>::res;
};
template<int N> struct Pow<N,0U> {
static unsigned long const res = 1;
};
template<class T, int N, int Dims> class MyArray
{
std::vector<T> data;
public:
MyArray() : data(Pow<N,Dims>::res) {}
};
int main() {
MyArray<int, 50, 3> i; // that's how you use it
}
(filling up 'MyArray' with indexing and other functionality is left as
an exercise)
Of course, that still leaves 'N' specified at compile-time. So, rewrite
this to specify it at run-time, as the argument to the constructor. You
won't need 'Pow' template (or, rather, you will need a different 'Pow'
template).
Good luck!
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
==============================================================================
TOPIC: Different treatment of the NodeType of LinkedList in C++ and Java
http://groups.google.com/group/comp.lang.c++/t/f3cf235e1c61e0af?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Oct 28 2009 2:14 pm
From: "yangsuli@gmail.com"
Hi, everybody;
I am a student who is taking the data structure course. When we are
learning the data structure LinkedList, I noticed that Java and C++
treated the type of the node of Linkedlist differently.
In STL, C++ actually publishes the typed of list_node:
class List{
protected:
typedef __list_node<T> list_node:
....
}
But in Java, the class of LinkedListNode has package access, so the
user of LinkedList won't even see this node type.
Personally, I wound think the type of node is the implementation
detail, and the best practice is to hide it from the user.But I am
posting this message to see, is there any particular reason that C++
choose to publish the list_node type? Does this has something to do
with the difference in this two languages?
Any answer would be appreciated!
Thank you very much!
== 2 of 2 ==
Date: Wed, Oct 28 2009 2:49 pm
From: peter koch
On 28 Okt., 22:14, "yangs...@gmail.com" <yangs...@gmail.com> wrote:
> Hi, everybody;
>
> I am a student who is taking the data structure course. When we are
> learning the data structure LinkedList, I noticed that Java and C++
> treated the type of the node of Linkedlist differently.
>
> In STL, C++ actually publishes the typed of list_node:
Nit: I assume you mean the standard C++ library. STL is a nonstandard
library probably not used very much anymore.
> class List{
> protected:
> typedef __list_node<T> list_node:
> ....
>
> }
No it does not. I don't know where you got the above from, but it is
not part of the standard library. For one difference, the name is
(std::)list, not List.
>
> But in Java, the class of LinkedListNode has package access, so the
> user of LinkedList won't even see this node type.
>
> Personally, I wound think the type of node is the implementation
> detail, and the best practice is to hide it from the user.But I am
> posting this message to see, is there any particular reason that C++
> choose to publish the list_node type? Does this has something to do
> with the difference in this two languages?
std::list "publishes" the name of the template type so that you can
use it in case your own code is templated. I very much doubt that any
implementation would publish the internal nodetype.
/Peter
==============================================================================
TOPIC: Member initialisation and construction
http://groups.google.com/group/comp.lang.c++/t/92df4caacc840728?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 5:51 pm
From: Taras_96
So to recap.
* The compiler generated default constructor is a constructor with an
empty initializer list and body
* If a constructor ommits a member from the initialization list:
** If the entity is a nonstatic data member of (possibly cv-qualified)
class type (or array thereof) or a base
class, and the entity class is a non-POD class, the entity is default-
initialized (8.5).
** Otherwise, the entity is not initialized
Foo foo; // default initialization
The default constructor is called (regardless of whether it is user
defined or not)
Foo foo = Foo(); // value initialization
If there IS a user declared constructor, it is called (and program is
ill formed if there is no default constructor)
If a non-union class type without a user-declared constructor, then
every non-static data member and base-class component of T is value-
initialized;
So, 'int Foo::x; will not be initialized IF:
- foo is default initialized and the compiler generated default
constructor is used
- foo is default initialized and a user generated default constructor
is used, *and* Foo::x is ommitted from the initializer list
- foo is value initialized and a user generated default constructor is
used, *and* Foo::x is ommitted from the initializer list
NB: int Foo::x WILL be initialized if foo is value initialized, and
there is no user declared default constructor (unlike if you were to
default initialize foo), as "every non-static data member and base-
class component of T is value-initialized"
This to me is unusual that the behaviour wasn't made consistent... why
not just make it so that all members are always initialized,
regardless of whether the parent object is default initialized, value
initialized, or if a user declared constructor is used.
Taras
==============================================================================
TOPIC: help with namespace/friend error
http://groups.google.com/group/comp.lang.c++/t/5eded7db20190481?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Oct 28 2009 5:54 pm
From: Joe
Shouldn't I be able to use a friend function like below? I'm getting
the following compiler errors in XCode 3 …
'test' was not declared in this scope
'double AB::test(double, double)' should have been declared inside 'AB'
Seems like this might have something to do w/ my namespaces. I've tried
to include everything I thought relevant to this problem.
--- BN.h ---
namespace AB {
class BN
{
public:
friend double test(double a, double b);
};
}
--- BN.cc ---
// error on next line … 'double AB::test(double, double)' should have
been declared inside 'AB'
double AB::test(double a, double b)
{
return
};
--- AL.h ---
namespace AB {
class AL : public BL
{
public:
AL();
};
}
--- AL.cc ---
using namespace std;
// constructor
AB::AL::AL() : BL() {
// error on next line … 'test' was not declared in this scope
test();
};
In case the above looks strange, I've double checked for any typos, and
it's all right (left out forward declarations, headers, etc...). This
used to compile in XCode 2.
== 2 of 2 ==
Date: Wed, Oct 28 2009 7:05 pm
From: "Johannes Schaub (litb)"
Joe wrote:
> Shouldn't I be able to use a friend function like below? I'm getting
> the following compiler errors in XCode 3 …
>
> 'test' was not declared in this scope
> 'double AB::test(double, double)' should have been declared inside 'AB'
>
> Seems like this might have something to do w/ my namespaces. I've tried
> to include everything I thought relevant to this problem.
>
> --- BN.h ---
> namespace AB {
> class BN
> {
> public:
> friend double test(double a, double b);
> };
> }
>
> --- BN.cc ---
> // error on next line … 'double AB::test(double, double)' should have
> been declared inside 'AB'
> double AB::test(double a, double b)
> {
> return
> };
>
> --- AL.h ---
> namespace AB {
> class AL : public BL
> {
> public:
> AL();
> };
> }
>
> --- AL.cc ---
> using namespace std;
>
> // constructor
> AB::AL::AL() : BL() {
> // error on next line … 'test' was not declared in this scope
> test();
> };
>
> In case the above looks strange, I've double checked for any typos, and
> it's all right (left out forward declarations, headers, etc...). This
> used to compile in XCode 2.
It's wrong because a friend function declaration just declares a function as
a friend, but it will never introduce a visible name into an enclosing scope
(the name is introduced, but it's *not* visible). Argument dependent lookup
is a special case, in which the function name introduced by that declaration
is visible in its namespace.
This means, you have to declare it yourself in AB before you define it
outside of it.
==============================================================================
TOPIC: Standard Template Library or C?
http://groups.google.com/group/comp.lang.c++/t/4494f3354c2a601f?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 7:10 pm
From: Puppet_Sock
On Oct 21, 6:47 pm, Johnson <gpsab...@yahoo.com> wrote:
> I am writing a cross-platform program that deals with huge data set. The
> program requires high efficiency, high data safety, and good portability
> (for both PC and ARM hardware platform, Windows and Linux OS). Now I
> have two options to do the job, either using pure C (with pointers and
> dynamic allocated memory) or STL.
[snip]
I would suggest that, at least as presented, your spec if inadequate.
You say you need high efficiency. This is literally of no meaning.
High compared to what? By what scale? You need to specify some kind
of numerical value you can test. Then you need to do some prototype
testing to see if this numerical value is in fact achievable by
any means. If you can't get there from here no matter what you do,
then you need to go back to your client sooner rather than later and
re-set the spec.
The spec might be something like "convert 1000 records from external
to internal in not more than 43 seconds." If, with a representative
sample of records, nothing you can do can convert them in less than
400 seconds, you are toast from the start and need to re-do the spec.
Or, if you can't renegotiate, then punt on the project. Possibly
by quitting and finding a new job.
All of your spec needs to be in objective, clear, testable format.
Otherwise it's just going to turn into a big shoving match with
the client over whether you have satisfied the spec. Numbers or
conditions for everything, along with specific limits or tests.
Regarding portability: The primary thing there is likely to be the
special purpose libraries you add onto whatever language you use.
The language itself is unlikely to restrict you too badly, as long
as you restrict to the core parts of the language, and stay away
from stuff that is flaky on some compilers.
If your database libs can be called from either C or C++, then it's
likely to be indifferent. If you are doing window-interface type
stuff, then again, those libs are going to be a choke point.
If you can use those libs in all your platforms with either language,
then again, it's a wash. And so on. If you can only use one language
to easily do any part of that, then that's a push for that language.
Regarding what you talked about as "data safety" the primary thing
is going to be familiarity with the language. If your developer
team is loaded up with one language and less familiar with the
other, then that is a possible guide to what language to use.
Or you can get developers for one language but not the other.
Socks
==============================================================================
TOPIC: \(0^◇^0)/Whoelsale 2009Newest Fashion Lady Juciy,Edhardy Coat,Sweater,
Christina Audigier Long Tshirts, LV Boots, Christian Louboutin High heal
http://groups.google.com/group/comp.lang.c++/t/15fd1a268df98ab1?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Oct 28 2009 8:27 pm
From: peng Selina
\(0^◇^0)/Whoelsale 2009Newest Fashion Lady Juciy,Edhardy Coat,Sweater,
Christina Audigier Long Tshirts, LV Boots, Christian Louboutin High
heal
"Coat (www.toptradea.com)
Edhary-Coat (www.toptradea.com)
Juicy-Coat (www.toptradea.com)
Sweater (www.toptradea.com)
Juicy-Sweater (www.toptradea.com)
Edhardy-Sweater (www.toptradea.com)
High Heels (www.toptradea.com)
Edhardy-High-Heels (www.toptradea.com)
Louboutin-High-Heel (www.toptradea.com)
Louboutin-Heel-New (www.toptradea.com)"
"Handbag {www.toptradea.com & www.toptradea.606c.com}
Burberrys Handbag {www.toptradea.com & www.toptradea.606c.com}
Prada Handbag {www.toptradea.com & www.toptradea.606c.com}
Juicy Handbag {www.toptradea.com & www.toptradea.606c.com}
Ed hardy Handbag {www.toptradea.com & www.toptradea.606c.com}
DB Handbag {www.toptradea.com & www.toptradea.606c.com}
Chloe Handbag {www.toptradea.com & www.toptradea.606c.com}
LV Handbag {www.toptradea.com & www.toptradea.606c.com}
Jimmy Hoo Handbag {www.toptradea.com & www.toptradea.606c.com}
Fendi Handbag {www.toptradea.com & www.toptradea.606c.com}
Coach Handbag {www.toptradea.com & www.toptradea.606c.com}
Gucci Handbag {www.toptradea.com & www.toptradea.606c.com}
Chanel Handbag {www.toptradea.com & www.toptradea.606c.com}
D&G Handbag {www.toptradea.com & www.toptradea.606c.com}
"
==============================================================================
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