I'm having a little trouble understanding what the slicing problem is.
In B.S.'s C++ PL3rdEd he says
"Becayse the Employee copy functions do not know anything about Managers,
only the Employee part of Manager is copied. "....
and gives the code above as
.....
Employee e = m;
e = ml
I fail to see how this is a problem as we are "casting" m into e and
obviously Employee shouldn't copy anything of m into e because that is not
already in e itself(where would it go?)?
I was thinking that "slicing" refered to an object being "sliced" in half by
not being copyied all the way so it would be seem that if we did something
like
Manager m = e;
then we would have "sliced" m in half by only assigning those elements of m
that are also of e?
This seems strange to me though.
By analogy if a derived object is larger than its base and we are casting
from a derived object into its base then we are "slicing" off the parts of
the derived object that don't fit into the base? But isn't that the whole
point? Else we wouldn't do the code to do the slice in the first place?
Maybe I'm making it into a problem when its not? It just mentions that it
can be a source of suprices and errors but I don't see how unless someone
isn't really thinking about what is happening.
If I do something like:
Derived D;
Base B = D;
then potentially I see how that Derived could change a value that I normally
except Base wouldn't not expect to see.
struct Base
{
int data;
Base(int i) : data(i) {};
};
struct Derived : public Base
{
int new_data;
Derived(int i) : Base(i+1), new_data(4) {};
};
void main()
{
Derived D(1);
Base B = D;
return;
}
then, lets suppose that Base's data is never suppose to be > 1...
but B has B.data = 2 after the assignment and hence hence there is an error.
Is that the basic idea?
Thanks,
Jon
Sep 20 '05
17 16606
Jon Slaughter wrote: I suggest you really loose your attitude and also stop spreading mis-information. You say my whole problem is based on a misconception of a cast yet you obviously seem to have a misconception of your own. I suggest you read C++ 3rd Ed page 407-408. Your ego seems to be a little bloated.
You know what?
If I make a mistake and use a word in a way it can't be used and somebody
corrects me and goes into great detail to explain to me what is wrong with
my usage and why it can't be used in that context, I say: "Thank you"
Your milage obviously varies as you showed in some other threads.
--
Karl Heinz Buchegger kb******@gascad .at
On Thu, 22 Sep 2005 18:14:39 -0500, "Jon Slaughter"
<Jo***********@ Hotmail.com> wrote: Basicaly, Jack saw an oppurtunity to show his ego and he did.
I still fail to see anything in Jack's post which might have anything
to do with his ego. And I'll leave it at that.
*plonk*
--
Bob Hairgrove No**********@Ho me.com
"Bob Hairgrove" <in*****@bigfoo t.com> wrote in message
news:c2******** *************** *********@4ax.c om... On Thu, 22 Sep 2005 18:14:39 -0500, "Jon Slaughter" <Jo***********@ Hotmail.com> wrote:
Basicaly, Jack saw an oppurtunity to show his ego and he did. I still fail to see anything in Jack's post which might have anything to do with his ego. And I'll leave it at that.
Well, You might be right to some degree but there is a tint of it somewhere
in there. Its along the same lines as when someone points out something in
the code as being wrong when it has absolutely nothing to do with the
problem and acting like that is the whole problem. Now, whether he
intentionaly does it or not is a different story. But to assume that the
other person you are trying to help is an idiot because they are asking for
help isn't being very nice. The whole point being that he is assuming my
whole problem is because I misused a word which is completely wrong. The
problem is that to many people in here are trying to find fault with the
persons response instead of trying to help them. Do you think it would be
appropriate for me to reply to someone asking for help by pointing out all
there spelling and grammar mistakes? Do those pertain to the original
problem?
I guess the problem is that I fail to understand that most of you guys spend
the majority of your life with computers instead of real people and don't
interpersonal communication skills. Sorry. But on the other hand, then, I
don't like to be talked to like a computer ;/ Sorry if I took offense by
that ;/
Jon
*plonk*
-- Bob Hairgrove No**********@Ho me.com
"Old Wolf" <ol*****@inspir e.net.nz> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com... Jon Slaughter top-posted: I suggest you really loose your attitude and also stop spreading mis-information. You say my whole problem is based on a misconception of a cast yet you obviously seem to have a misconception of your own. I suggest you read C++ 3rd Ed page 407-408. This newsgroup is for discussing ISO Standard C++. The words of the Standard have more importance than the words of some other document.
If I didn't know the meaning of the word "deer", would you refer me to a modern dictionary, or to Shakespeare?
Section 5.4 of the Standard defines "cast" as "explicit type conversion".
First off it doesn't matter what term I use if as long as the concept behind it is adequate...
Obviously it's not adequate, otherwise this discussion would never have got started. Further, by your definition,
Thats not true, as you should know. Lots of people just like attention(and
I'm not trying to be one of those people by starting this thread either, I
hope). As you have pointed out "cast" = "explicit type conversion"!!!!
there you go. So if I happen to use it as "cast" = "implicit type
conversion" and you jump all over me then thats your problem... not mine.
the point is that both uses deal with conversion and that my "misconcept ion"
is not 100% over the use of a damn word like Jack wants me to believe.
Why was it so hard for him to point out that "Casting is stated as an
explicit converion and when it is implicit we just say conversion" or
something like that?
I can't believe that you guys fail to see that whether I used the word
"casting" or "conversion " they are related... maybe there is a synatical
difference but that doesn't mean that my whole understanding of somethign is
wrong. As I said before, its fine to point out the difference but to make
it into the issue when it is not is the problem.
char *ptr = 0; or long two = 1 + 1;
is a cast. This doesn't seem like a very useful definition to me. Third, It doesn't matter if its an implied cast or if its an explict cast, its still a cast.
You're 100% wrong. It might not matter to you if you call a lemon an orange, but it matters when other people are tring to understand you.
A cast is a conversion from one type to another... its that simple. You're making a basic logic error: although all casts are conversions, not all conversions are casts. Here's another example of the same error:
Yeah, but you fail to realize many things. First I put cast in quotes which
means that its not the exact same. jesus christ... second he could easily
have pointed out the difference, third, the problem is slicing had nothing
to do with my "misconcept ion" of casting because the meaning of casting is a
proper sub category of conversion.
Even your logic above is wrong.
the meaning of casting is a subcategory of conversion, it is a derived
meaning of the meaning of conversion and hence has some resemblence of
conversion...
maybe NOT every conversion is a cast BUT SOME are! Your logical fallicy is
to think believe that no cast is a conversion and hence I am wrong is using
what I did.
AS I SAID BEFORE, IT HAS NOTHING TO DO WITH IF I USED THE PROPER WORD OR
NOT! If you would get that through your head.. the original problem doesn't
matter if I use cast or conversion.. If I replaced the original post with
the proper use of casting do you think it would have made the problem go
away? (well, I guess it would have made Jack go away but I still would have
the EXACT same problem).
"A cat is an animal... its [sic] that simple. It doesn't matter if its a small furry animal, or a slimy underwater animal, its still a cat."
You wouldn't look so stupid if you didn't have such an ego.
You would have a bit more credibility if you started following the etiquette of this NG, in particular, not top-posting.
OMG, here we go again... so my whole argument is wrong because I top-posted?
Theres a reason I top posted... I'll let you figure it out though.
"persenaama " <ju***@liimatta .org> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... You're 100% wrong. It might not matter to you if you call a lemon an orange, but it matters when other people are tring to understand you.
Yadda yadda yadda.. so he haven't *talked* about the concepts too much apparently and called *type* conversion casting, big deal move on already.. how many here honestly, when things get downright *rough* haven't resorted to whipping open a copy of the Standard document? Thought so.
Exactly. They act like its the end of the world or something because I
misused a word... because I'm not perfect... and instead of actually helping
me they will run around spending there time looking up definitions to prove
there point and claim that my whole problem stems from my lack of proper use
of the definitions.
Its amazing to me. This seems like a trend amoung programmers... Maybe all
that coffee makes there brain into an anus(heh, I mean, makes them anal).
I'm glad atleast someone understand what I'm trying to point out. Thanks.
Jon
"Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message
news:43******** *******@gascad. at... Jon Slaughter wrote: I suggest you really loose your attitude and also stop spreading mis-information. You say my whole problem is based on a misconception of a cast yet you obviously seem to have a misconception of your own. I suggest you read C++ 3rd Ed page 407-408. Your ego seems to be a little bloated. You know what? If I make a mistake and use a word in a way it can't be used and somebody corrects me and goes into great detail to explain to me what is wrong with my usage and why it can't be used in that context, I say: "Thank you"
Yeah, I agree completely. But do you realize there is a right way and a
wrong way to do this? Specially if its no real fault of my own... I take
B.S. as an authority because he pretty much wrote C++ and so if he uses
casting similar to what I have used then I assume I am correct... and if not
then sure, I have no problem with someone pointed it out.
First off, though, its funny how some of these guys resort to the C++ ISO
standard as the bible and then make a huge issue out of things that do not
really pertain to the real problem.... fine to point out the little issues
but to make it THE issue is plain wrong.
Again, as I have said probably 10 times already, ITS HOW YOU DO IT!! If
someone, and that includes anyone, comes in here to ask for help they do not
deserve to have to deal with this crap(if there question is legit).
Point out the problem but don't act like your some gods gift to
comp.lang.c++. Don't try and act like you are above the person you are
trying to help just because you know more about that subject. I as a tutor
for about 5 years and I'm sure if I acted like that I would have been
slapped eventually, at the very least no one would ask for help from me.
Whole point of helping is to help.. if you don't like helping then don't.
If you get pissed off because someone uses a wrong word then don't help. If
you are so anal about that kinda stuff then don't help... if everyone was
perfect like "you" then they wouldn't be asking for help.
The problem I had, which I might have slightly blown out of proportions,
which I apologize if I did, is
"------------
You are not "casting" anything. A cast in C++ is performed only by
one of the cast operators, either the C style cast or one of the newer
type of classes. You cannot cast aggregate (arrays, classes, structs)
at all. You can only cast built-in scalar types (integer types,
floating point types, and pointers).
A cast is an explicit conversion. What is happening in your snippet
above is an automatic conversion caused by assignment. There is no
cast involved.
----------"
When I read this I feel as if he is showing his ego... this is very hard to
tell because, ofcourse, I don't know him and because its only computer
text... but if you read it, it seems as if he is saying that my use of
casting is completely wrong... but this isn't the case.
double d = 3.2;
int i = d;
and
double d = 3.2;
int i = (int)d;
are exactly the same code? hmm, one as an explicit cast and one as a
"implicit" conversion... to me, I know that the first on is "casting"
because the types are different, and if you want to call it "implicit
conversion" to be pedantic then go ahead. But that doesn't mean the concept
behind the two are different. Do you think the compiler really see's a
difference? It knows d and i are different and it has to do a
"conversion "... it inserts the "(int)" behind the scenes? So just because
there is one level of abstraction taking away doesn't mean there is a HUGE
difference that Jack wants me to think.. Technically they have defined it to
mean something very precise but that doesn't mean that if one uses it in an
imprecise way then everything is wrong.
Thats all I'm trying to get across. If you understand the above then you
understand that Jacks point that my own problem is about casting is a little
wrong... and the "You are not "casting" anything" is kinda crap... because
whether I called it casting or converting has nothing to do with the
original problem.
Your milage obviously varies as you showed in some other threads.
Well, I just don't like this kinda crap. My impression is that people like
Jack, Victor, and others seem to think they are better than the rest of us.
Hell, even if they are they have no right to act like it... because if they
do then I have every right to try my best to put them in there place.
Normally I would not do something like that because I don't want to take
things out of context and misinterpret them... but seeing how rampant people
with ego's are on this board I'd rather take that chance. Not for my own
benifit but for others. I could care less about Jacks response and intially
just ignored it for 3 days. I have ignored others before because of that
crap... but then see them do it to others.
I guess programmers aren't taught "If you don't have anything nice to say
don't say it at all"? Again, when you are communicating with people you
have to say things in a way that won't hurt there feelings, etc...
Specially when someone is wrong then you have to show them they are without
making them feel stupid. If you go out of your way to do that then you
deserve whatever you get... if you just imply it you do deserve some of it
too. Jack was a not as bad as most but he's still trying to show how smart
he is. Again though, I don't know Jack and so I could have been completely
wrong... but how you say things is very important and you should do your
best to say them so you don't offend people.
For example, if you were a hostage negotiater you would have to be very
careful not to piss of the bad guys... you try to correct them on there
grammar, for example, or make them feel stupid will just get you fired. I
have no problem with Jack if he wants to be an asshole, say, but if he does
then he deserves the consequences... and again and again and again, he
doesn't have to help if he has to add all that extra bs in it. Though,
ofcourse, maybe english isn't his first language and he has problems with
wording things so they are taking to be mean or arrogant or whatever. If
thats the case then he should learn.
Anyways, I'm not so pissed off at Jack for the way he said it rather than
what he said... basicaly trying to make the issue about some definition when
it pretty much nothing to do with it. Sure, point out my problem and
correct it as simply and quickly as possible then move onto the real problem
and assume that I'm not an idiot(because thats what he assumes, its implied
in the context of that paragraph I quoted).
Jon
-- Karl Heinz Buchegger kb******@gascad .at
Jon Slaughter wrote: "Old Wolf" wrote: Jon Slaughter top-posted: I suggest you really loose your attitude and also stop spreading mis-information. You say my whole problem is based on a misconception of a cast yet you obviously seem to have a misconception of your own. I suggest you read C++ 3rd Ed page 407-408.
Why was it so hard for him to point out that "Casting is stated as an explicit converion and when it is implicit we just say conversion" or something like that?
Er, he did. In fact here are his exact words:
A cast is an explicit conversion. What is happening in your
snippet above is an automatic conversion caused by assignment.
He then went on to explain (politely, IMHO) how slicing comes
about, giving an example with int and double, and then an
example with class types. A cast is a conversion from one type to another... its that simple.
You're making a basic logic error: although all casts are conversions, not all conversions are casts. Here's another example of the same error:
Yeah, but you fail to realize many things. First I put cast in quotes which means that its not the exact same. jesus christ...
"I see"
second he could easily have pointed out the difference,
He did (see above)
Even your logic above is wrong.
the meaning of casting is a subcategory of conversion, it is a derived meaning of the meaning of conversion and hence has some resemblence of conversion...
maybe NOT every conversion is a cast BUT SOME are! Your logical fallicy is to think believe that no cast is a conversion and hence I am wrong is using what I did.
Huh? All casts are conversions. I've said this repeatedly, I don't see
how you get "no cast is a conversion" from it.
AS I SAID BEFORE, IT HAS NOTHING TO DO WITH IF I USED THE PROPER WORD OR NOT! If you would get that through your head..
You seem to be still trying to defend your position that implicit
conversions are casts. You need to get through your head that
that is wrong; only explicit conversions are casts.
the original problem doesn't matter if I use cast or conversion.. If I replaced the original post with the proper use of casting do you think it would have made the problem go away?
It would have made this sub-thread go away. I couldn't care less
about the original problem. I am posting to correct your
misconception about the meaning of the word "cast". Also I am
partly motivated by your abusive reply to Jack Klein, who initially
answered your question (and you seem to have difficulty accepting
when you make a mistake).
well, I guess it would have made Jack go away but I still would have the EXACT same problem.
If you took in the information in Jack's message, instead of
flaming him, then you wouldn't have the problem any more. You would have a bit more credibility if you started following the etiquette of this NG, in particular, not top-posting.
OMG, here we go again... so my whole argument is wrong because I top-posted?
Please read what people say instead of putting words in their
mouth (fingers?) and then flaming them for it. I said "bit more
credibility", not "whole argument is wrong".
Theres a reason I top posted... I'll let you figure it out though.
Laziness?
hmm..
You still completely fail to realize that he was making a huge issue out of
nothing... as I have pointed out so many times. Read persenaama's post if
you can't understand mine.
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steven Bethard |
last post by:
Anyone know why deques don't support slicing?
>>> from collections import deque
>>> d = deque(i**2 - i + 1 for i in range(10))
>>> d
deque()
>>> d
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sequence index must be integer
|
by: Jerry Sievers |
last post by:
Fellow Pythonists;
I am totally puzzled on the use of slicing on mapping types and
especially unsure on use of the Ellipsis... and slicing syntax that
has two or more groups seperated by comma.
I am referring to (from the manual);
Slice objects
Slice objects are used to represent slices when extended
|
by: Christian Stigen Larsen |
last post by:
Consider the following:
class parent {
public:
virtual void print() {
printf("Parent\n");
}
};
class child : public parent {
|
by: Bryan Olson |
last post by:
I recently wrote a module supporting value-shared slicing. I
don't know if this functionality already existed somewhere, but
I think it's useful enough that other Pythoners might want it,
so here it is.
Also, my recent notes on Python warts with respect to negative
indexes were based on problems I encoutered debugging this
module, so I'm posting it partially as a concrete example of
what I was talking about.
|
by: jbperez808 |
last post by:
>>> rs='AUGCUAGACGUGGAGUAG'
>>> rs='GAG'
Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs='GAG'
TypeError: object doesn't support slice assignment
You can't assign to a section of a sliced string in
Python 2.3 and there doesn't seem to be mention of this
as a Python 2.4 feature (don't have time to actually try
| |
by: baibaichen |
last post by:
i have written some code to verify how to disable slicing copy
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit B(INT32 i =0):i_(i){}
virtual ~B(){}
|
by: Bart Simpson |
last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual
constructor" idiom as explain at parashift ?
From parashift:
class Shape {
public:
virtual ~Shape() { } // A virtual destructor
|
by: Rahul |
last post by:
Hi Everyone,
I was working around object slicing (pass by value) and was
wondering how it is specified in the standard,
class A
{
};
class B: public A
|
by: subramanian100in |
last post by:
Consider
class Base
{
....
};
class Derived : public Base
{
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |