|
|
Up |
|
|
  |
Author: Alf P. SteinbachAlf P. Steinbach
Date: Dec 15, 2007 22:09
* George2:
> Hello everyone,
>
>
> I am reading some code from other people, there are some code like
> this,
>
> [Code]
> class Foo {
>
> };
>
> Foo& func()
> {
> Foo foo;
> return foo;
> }
>
> int main()
> { ...
|
| Show full article (1.10Kb) |
|
| |
no comments
|
|
  |
Author: yanlinlinyanlinlin
Date: Dec 15, 2007 22:07
On 12月16日, 下午1时49分, George2 yahoo.com> wrote:
> Hello everyone,
>
> I am reading some code from other people, there are some code like
> this,
>
> [Code]
> class Foo {
>
> };
>
> Foo& func()
> {
> Foo foo;
> return foo;
>
> }
>
> int main()
> { ...
|
| Show full article (0.68Kb) |
|
| |
2 Comments |
|
  |
Author: tragomaskhalostragomaskhalos
Date: Dec 15, 2007 15:14
On 15 Dec, 13:57, Pete Becker versatilecoding.com> wrote:
> On 2007-12-15 04:36:30 -0500, tragomaskhalos
> logicacmg.com> said:
>
>> OK, my original reply wasn't detailed enough.
>> Others have said that this is UB but you are quite correctly
>> still wondering why it happend to work with your compiler.
>> The key is that the compiler is likely producing code something akin
>> to this:
>
> Maybe. Speculating about why something whose behavior is undefined
> happens to do what a naive programmer guessed it would do is generally
> pointless. Undefined means undefined. Nothing more. The reason that it
> "works" is pure accident. (That's the screed for beginning and
> intermediate programmers.)
>
|
| Show full article (1.20Kb) |
|
no comments
|
|
  |
Author: Vladislav.LazarenkoVladislav.Lazarenko
Date: Dec 15, 2007 10:57
Could you please give me his email? He seems to be a nice guy from
your words. I would like to speak with him. Thanks in advance.
|
| |
|
no comments
|
|
  |
Author: James KanzeJames Kanze
Date: Dec 15, 2007 09:20
On Dec 15, 3:00 am, "Bryan Parkoff" nospam.com> wrote:
> "James Kanze" gmail.com> wrote in message
> news:fd588cf4-cb2c-4c04-9c1b-9aeab14d8587@d4g2000prg.googlegroups.com...
> On Dec 14, 4:13 am, "Bryan Parkoff" nospam.com> wrote:
>>> We discussed about the union keyword on the previous threads
>>> 2-3 days earlier. I want to add. Two byte data inside struct
>>> and one word data are inside union. You modify word data.
>>> Then two byte data are modified automatically because two byte
>>> data and one word data are sharing the same memory address.
>>> Let's move on and forget union because we claim that union
>>> keyword is not the language of C/C++ Compiler.
>>No one ever said that union wasn't a keyword in C++ (or in C).
>>> Here is a pointer variable code below.
>>> enum
>>> {
>>> Low = 0,
>>> High = 1
>>> };
>>> U_BYTE B[4] = { 0xFF, 0x20, 0x02, 0x22 };
>>> PU_WORD W = (PU_WORD)&B; ...
|
| Show full article (7.97Kb) |
|
no comments
|
|
  |
Author: Abhishek PadmanabhAbhishek Padmanabh
Date: Dec 15, 2007 04:51
On Dec 15, 4:32 am, massysett gmail.com> wrote:
> Hello,
>
> I've got a couple of simple functions to examine a vector of strings,
> removing from the vector strings that do not begin with a particular
> string. They compile just fine when they look like this:
>
> #include
> #include
>
> bool startswith(std::string subject, std::string test)
> {
> return (subject.substr(0, test.length()) == test);
>
> }
>
> std::vector matchAbbrev(std::vector strings,
> const std::string& abbrev)
> {
> // isolate all words with abbrev as a prefix ...
|
| Show full article (1.59Kb) |
|
no comments
|
|
  |
Author: massysettmassysett
Date: Dec 15, 2007 04:45
On Dec 15, 3:46 am, werasm gmail.com> wrote:
> You've omitted to included and and for that
> reason your code does not compile (at least the posted code).
Yes, thanks for pointing that out (only noticed right after I
posted...)
> Apart from that, use const references. Changing the binary
> function declaration to:
|
| |
|
1 Comment |
|
  |
Author: Roland PibingerRoland Pibinger
Date: Dec 15, 2007 04:36
On Thu, 13 Dec 2007 18:41:57 -0800 (PST), hostilefork@ gmail.com wrote:
>But one thing I really did get obsessed with while
>programming C++ was how I could aggressively use const to enforce
>rules at compile time. Specifically, I was using the "transitive"
>nature to get access control at a level more powerful than the public/
>private/protected keywords.
>
>I wrote an essay a long time ago that I finally posted on my blog--and
>I thought maybe someone here would have comments or critiques:
>
> http://hostilefork.com/2005/02/10/transitive-power-of-const-in-cpp/
>
>I don't know if this is what you'd conisder innovative, or an abuse,
>or an "obvious" application. So I just wanted to share the idea.
>Please feel free to comment. There are a few other C++ related
>articles on the site as well...
|
| Show full article (1.20Kb) |
|
no comments
|
|
  |
Author: Juha NieminenJuha Nieminen
Date: Dec 15, 2007 03:22
George2 wrote:
> I am wondering the default implementation of assignment operator (e.g.
> when we do not implement assignment operator in user defined class,
> what will be returned? temporary object? reference or const reference?
> deep copy or shallow copy is used in default assignment operator?)?
The compiler cannot automatically generate a deep-copying of the
objects because it has absolutely no way of knowing whether the member
pointers are pointing at memory allocated and owned by the object
itself, or whether they are just pointing to something else (for example
trying to deep-copy an element of a doubly-linked list would be quite a
bad idea).
The default assignment operator simply assigns each individual member
variable from the parameter to this, regardless of what it is. If it's
eg. a pointer, then a simple pointer assignment will be done.
In many cases the default assignment operator is ok, especially if the
class does not contain pointers.
It returns a const-reference to *this.
|
| |
|
2 Comments |
|
  |
|
|
  |
Author: Markus MollMarkus Moll
Date: Dec 15, 2007 03:20
> Ok, so I understand that its undefined behavior. However, is the
> garbage this pointer dereferenced to call the member method?
That's just one of the things that is undefined.
Markus
|
| |
|
no comments
|
|
|
|
|