Author |
Topic  |
|
diavo
Senior Member
  
Germany
31 Posts |
Posted - Jul 19 2006 : 03:18:57 AM
|
given the following example:
class Test
{
Test(int member1) : member(member1) {};
int member;
};
class Test
{
Test(int member) : member(member) {};
int member;
};
If you try to rename the member variable of the first example, all works fine. If you try to rename the member variable of the second example, the member variable in the init list of the constructor will not be renamed. I know, that's maby dirty code, but it is valid c++ code, too. And so it should work. |
|
bugfix
Tomato Guru
    
Germany
324 Posts |
Posted - Jul 19 2006 : 12:08:43 PM
|
quote: Originally posted by diavo I know, that's maby dirty code, but it is valid c++ code, too. And so it should work.
Not only maybe it definitely is bad style and prone for bugs/sideeffects. |
http://www.mf-sd.de |
 |
|
diavo
Senior Member
  
Germany
31 Posts |
Posted - Jul 20 2006 : 01:57:25 AM
|
Yes sure, but for example, Microsoft use this in many examples in their MSDN. |
 |
|
bugfix
Tomato Guru
    
Germany
324 Posts |
Posted - Jul 20 2006 : 05:07:57 AM
|
Heh, and b/c MS has zillion of bugs in their stuff you want them too? Beside those are examples not realworld code, no copy&paste w/o thinking code. ... and I've always thought error propagation is a numeric problem only:) |
http://www.mf-sd.de |
 |
|
feline
Whole Tomato Software
    
United Kingdom
19134 Posts |
Posted - Jul 20 2006 : 6:19:37 PM
|
i am SO tempted to reply "but if it compiles then it must be perfect code", but i shall try to resist.
a related bug, to do with duplicate names in different classes is listed as fixed in the next build, so that may help with this.
i do have to agree with bugfix, this is a terrible idea. how can you use one of the classes? or more accurately, if you do create an instance of the class, which one was it? |
zen is the art of being at one with the two'ness |
 |
|
jpizzi
Tomato Guru
    
USA
642 Posts |
Posted - Jul 21 2006 : 01:31:14 AM
|
I placed the code into a project in VS 2005. It does work. I examined the assembly and watched the values in the debugger.
Still, I would not do this in my code. I would try to educate anyone that worked for me that did this once. I would fire anyone that worked for me that did this more than once. |
Joe Pizzi |
 |
|
diavo
Senior Member
  
Germany
31 Posts |
Posted - Jul 21 2006 : 06:12:32 AM
|
Oh, I think you understand me wrong. The two classes are not in the same code. The two class are two !separat! examples. My problem was the renaming of the member variable in the initializing list in the constructor. To avoid misunderstandings here a different code again:
class Test
{
Test(int member1) : member(member1) {};
int member;
};
class Test1
{
Test1(int member) : member(member) {};
int member;
};
If you try to rename the member variable of the first example, all works fine. If you try to rename the member variable of the second example, the member variable in the init list of the constructor will not be renamed. |
 |
|
diavo
Senior Member
  
Germany
31 Posts |
Posted - Jul 21 2006 : 06:14:42 AM
|
or better:
class Test
{
Test(int member1) : member(member1) {};
int member;
};
class Test1
{
Test1(int member) : member(member) {};
int member;
};
|
 |
|
feline
Whole Tomato Software
    
United Kingdom
19134 Posts |
Posted - Jul 22 2006 : 12:47:05 PM
|
*ah* now i see what you are getting at, and i am still feeling quite "upset". my initial reaction was "that will never compile" but i can see how the compiler can manage to resolve this.
i can see why people are tempted to do just this, so i have put in a case for this one.
case=1767 |
zen is the art of being at one with the two'ness |
 |
|
|
Topic  |
|