- doubt with abstract data type list - 1 Update
- C++ condition variable confusion - 12 Updates
saulmartinezespinosa1@gmail.com: Mar 20 03:42PM -0700 Hi, I just started learning c++, in my classroom the teacher wrote code of static list using class template, the list is based on an array, it works fine for what was tried, integers, floats, strings and as well for abstract data (classA), because he wrote also a class that has one integer, one float and one string so the class template list is also able to work with that abstract data type, everything was tried in the same console application and worked fine, my questions for abstract data type, how or where this list store those data, I moreless understand how it works with the template for integers, floats and strings but I can not understand how it does for the 3 data types at the same time, I mean in a classA datatype together. For example if data is integer with the template is like cresting an integer array, for floats it is like creating a float array, same for string, but what about classA datatype, does it create 3 arrays? one for integer, one for float and one for string? or it is a single array containing addresses to each of classA instances? Please help, I want to understand and I can not ask the teacher because it was supposed he already explained. Thanks //-----------you can see here the array that was used l[100] in staticlist hearder file-------------- template <class T1> class StaticList { private: int cont; T1 l[100]; template <class T1> StaticList<T1>::StaticList() { cont = 0; } //-----------here you can see how the adt classA was defined in classA header file -------------- class ClassA { private: int iInteger; string sString; float fFloat; public: ClassA(); ClassA(int, float, string); //------------ ClassA::ClassA(int a, float b, string c) { iInteger= a; fFloat= b; sString= c; } //------------in the main an instance is created------------- StaticList<ClassA> listClassA; |
James Kuyper <jameskuyper@alumni.caltech.edu>: Mar 19 08:42PM -0400 > On Sun, 17 Mar 2019 09:33:24 -0400 > Sam <sam@email-scan.com> wrote: ... >> That brain surgeon does not understand how wait() works, and why it's needed? > If I didn't understand why its needed sammy my little friend, I wouldn't be > trying to use it. I'm no expert on multi-threaded code, so I'll abstain from expressing any judgments on whether or not your understanding of wait() is correct. Also, I don't endorse Sam's insulting approach to this discussion. However, I don't see how you can justify that argument. If you misunderstood how wait() works, and misunderstood why it's needed, it seems entirely reasonable to me that you would use wait() in any context where your misunderstanding made using it seem, incorrectly, to be a reasonable thing to do. |
James Kuyper <jameskuyper@alumni.caltech.edu>: Mar 19 08:49PM -0400 On 3/19/19 18:02, Sam wrote: > Chris Vine writes: ... >> class system is well typed, but every class at the end of the day is >> formed from its built-in components. > Oh, I wasn't aware that you could assign a std::variant to a double, or Did anyone claim that you could? You can, however, assign a char to a double, and vice versa. > push_back an instance of MyClass into a std::vector<int>, just like that. You can if MyClass has implicit conversion into any standard type that can be implicitly converted to int. > I > guess I was wrong, and C++ is a weakly-typed language. Compared to languages where the equivalent of char c = 1.0; is illegal, and must be re-written as the equivalent of char c = char(1.0); C++ is weakly typed. |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 20 07:12AM On Tue, 2019-03-19, James Kuyper wrote: > On 3/19/19 06:11, Jorgen Grahn wrote: >> On Tue, 2019-03-19, James Kuyper wrote: ... >> that "weak" sounds like a bad thing). > Agreed. I was only addressing the question of whether C qualifies as a > strongly-typed langauge, not the desirability of doing so. Yes. I noticed that, but it was a problem with the upthread postings. The alternative term "loosely typed" would have been less controversial. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
David Brown <david.brown@hesbynett.no>: Mar 20 11:18AM +0100 On 20/03/2019 01:49, James Kuyper wrote: > is illegal, and must be re-written as the equivalent of > char c = char(1.0); > C++ is weakly typed. Note, however, that C++ /allows/ strong typing. It's base types are fairly weak, just like C where they originated. But you can easily make yourself types Char and Double that have very similar properties and uses as char and double - but which are strongly typed and cannot be implicitly converted. So while there is no doubt that C++ is weakly typed at its lowest level, it has support for strong typing. (It is a language that has support for a good deal of paradigms and strategies in programming, without insisting on their use.) |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 20 12:50PM +0100 On 20.03.2019 11:18, David Brown wrote: > it has support for strong typing. (It is a language that has support > for a good deal of paradigms and strategies in programming, without > insisting on their use.) Well, imagine a city where there are traffic lights, but its up to the car drivers whether to activate them and, when activated, obey them. That is, the city /supports/ clean safe traffic, it provides the necessary machinery, but it's all optional. The drivers can do that as an agreed on convention. If they wish, and manage to agree. That's safe, yes? Cheers!, - Alf |
David Brown <david.brown@hesbynett.no>: Mar 20 02:44PM +0100 On 20/03/2019 12:50, Alf P. Steinbach wrote: > necessary machinery, but it's all optional. The drivers can do that as > an agreed on convention. If they wish, and manage to agree. > That's safe, yes? Fortunately, C++ is only ever programmed by people who understand what they are doing, and program safely. And they never drunk-program. :-) |
Juha Nieminen <nospam@thanks.invalid>: Mar 20 02:47PM > is illegal, and must be re-written as the equivalent of > char c = char(1.0); > C++ is weakly typed. I'm not sure what your definition of "weakly typed" is, but I have always understood it as variables not having any particular type, and being able to hold values of any type (without losing any info about that value). So in a typical weakly typed language you don't specify the type of the variable, and instead use a syntax that's typically like var x = 5; // x holds an integer var y = "hello"; // y holds a string x = y; // ok, now x holds a string as well What you are talking about is implicit conversions, which I'm not sure are classically considered as related to weak/strong typing. But even if we were talking about implicit conversions as "weak typing", then C/C++ is only weakly typed among compatible types, so it's a very limited form of "weakly typed". --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
jameskuyper@alumni.caltech.edu: Mar 20 08:38AM -0700 On Wednesday, March 20, 2019 at 10:47:32 AM UTC-4, Juha Nieminen wrote: > > char c = char(1.0); > > C++ is weakly typed. > I'm not sure what your definition of "weakly typed" is, but I have always There are many possible definitions: <https://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_%22strong%22_or_%22weak%22> > var x = 5; // x holds an integer > var y = "hello"; // y holds a string > x = y; // ok, now x holds a string as well What you're talking about is called "latent typing". There's a link to the wikipedia page for "latent typing" on the wikipedia page about "strong and weak typing", but there's no other indication of a link between those two concepts. > What you are talking about is implicit conversions, which I'm not sure > are classically considered as related to weak/strong typing. "implicit conversions" is the first of four items listed under the section I gave a link to. I want to emphasize that I'm not claiming Wikipedia is absolutely authoritative. I just don't know of any other source that's any more authoritative than Wikipedia. In my experience, Wikipedia is fairly reliable when it comes to concepts related to computer science - more so, in fact, than traditional encyclopedias. And if you find an error in it, you're free to correct it (subject to review), which is an improvement over traditional encyclopedias. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 20 05:59PM On Wed, 20 Mar 2019 14:47:20 +0000 (UTC) > var x = 5; // x holds an integer > var y = "hello"; // y holds a string > x = y; // ok, now x holds a string as well That is called dynamic or latent typing, which can be strong or weak. The lisps and python are generally regarded as strongly and dynamically typed. Javascript is weak-ish (all these things are on a continuum) and dynamically typed. A strongly and dynamically typed language carries out much of its type checking at run time. That obviously affects when and how your type errors will propagate. The advantage of static typing is that type errors are detected at compile time. > But even if we were talking about implicit conversions as "weak typing", > then C/C++ is only weakly typed among compatible types, so it's a very > limited form of "weakly typed". I surprised there is any controversy about this. Languages which give programmers leave to subvert the type system, and in particular which provide implicit conversions and allow pointer conversions, are generally referred to as weakly typed. C goes further and has a void* type. That is one of the reasons why C and C++ are suitable for low-level systems programming and things which require maximum efficiency. But you can call it whatever you like. "Not strongly typed" would be fine. "Statically typed with loopholes" would also do. For C++ you could say "statically and dynamically typed with loopholes", because C++ has RTTI. |
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 20 01:57PM -0700 On 3/20/2019 6:44 AM, David Brown wrote: > Fortunately, C++ is only ever programmed by people who understand what > they are doing, and program safely. And they never drunk-program. > :-) Well, some people think that the following is necessary to protect people from themselves; cork on the fork, Steve Martin: https://youtu.be/SKDX-qJaJ08 C and C++ allows one to pop the proverbial cork? |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 20 10:17PM On Tue, 2019-03-19, Sam wrote: > response was written in reply to. Even more specific: the post in > question was a 100% content-free "you all suck" message; and my > reply was pretty much in the same vein. You were responding to a post from Ben, which was in response to the OP's <q6ltrr$tsn$1@gioia.aioe.org>. There's no "you all suck" theme in that one AFAICT; it's a perfectly reasonable on-topic posting. The OP /did/ whine a lot in other postings, but even those didn't deserve your reaction upthread. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 20 10:38PM On Wed, 2019-03-20, Chris Vine wrote: > On Wed, 20 Mar 2019 14:47:20 +0000 (UTC) > Juha Nieminen <nospam@thanks.invalid> wrote: ... > which provide implicit conversions and allow pointer conversions, are > generally referred to as weakly typed. C goes further and has a void* > type. For me at least, I think the problem is I last encountered strong/weak typing during my CS education[0] a long time ago. Then at work I never touched a strongly typed language: no Ada or Haskell, etc. Just languages with more or less loose type systems, with different tradeoffs. If you're comparing the languages you know and use, and find the C++ type system the most helpful of them, it's hard to swallow that it's classified as "weak". Even though I'm sure it /is/ according to the definition. > fine. "Statically typed with loopholes" would also do. For C++ you > could say "statically and dynamically typed with loopholes", because > C++ has RTTI. /Jorgen [0] gu.se; they were heavily into type system research at the time, in the various functional languages which became Haskell. -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment