|
You're right but I think it was a CP bug, not mine.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: it was a CP bug
Take the [PermaLink] to open a new window, and copy that new URL. It will solve!
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: and copy that new URL. It will solve!
how's that possible, do you hacked your domain server policy [^]

|
|
|
|
|
Rajkumar R wrote: how's that possible, do you hacked your domain server policy [^]
I'm home ~~~
Maxwell Chen
|
|
|
|
|
I told you it was a CP issue. Now it's working fine without my intervention.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: I told you it was a CP issue. Now it's working fine without my intervention.
Yes, indeed!
Maxwell Chen
|
|
|
|
|
Hi,
For some reason, I need to launch an application from my c++ code while holding the Alt key.
the code is really simple:
<br />
char appName[64];<br />
strcpy(appName,"c:\\WINDOWS\\notepad.exe");<br />
ShellExecute(hWnd,"open",appName,NULL,NULL,SW_SHOWNORMAL);<br />
But when executed whith the Alt key down, the application is opened behind the main window
Does anyone have any clue fro this ?
I appreciate your help.
Thanks
|
|
|
|
|
Hello everyone,
According to standard, the code should not compile.
http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
template <typename T> struct Base {
int i;
};
template <typename T> struct Derived : public Base<T> {
int get_i() { return i; }
};
But it can compile without any issues in Visual Studio 2008, without any warnings and even if I select disable language extensions to yes.
Any comments? What is wrong?
thanks in advance,
George
|
|
|
|
|
George_George wrote: According to standard, the code should not compile.
What do you mean with standard?
As far as I can tell the snippit looks fine. And i think that the manual is wrong on this one.
They state: In get_i(), i is not used in a dependent context according to me this is wrong since i is without any doubt the Base<T>::i which is known.
This is indeed a strange situation.
codito ergo sum
|
|
|
|
|
Thanks BadKarma,
Seems like Visual Studio is wrong. Please look at section 35.19 of,
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19[^]
1.
I think this line of statement matters, agree?
--------------------
the compiler does not look in dependent base classes (like B<T>) when looking up nondependent names (like f).
--------------------
2.
What disadvantage do we have if the code can compile?
regards,
George
|
|
|
|
|
I think current versions of VC++ treat this issue in the manner treating non-template name hiding stuff. Such as:
int a = 3;
for(int i = 0, a = 0; i < 2; i++) {
printf("a = %d \n", a);
}
printf("a = %d \n", a);
Result:
a = 0
a = 3
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
1. I think Visual Studio 2008 provides correct result in the sample you provided. Are there anything wrong?
2. Does your sample have anything related to my question?
regards,
George
|
|
|
|
|
George_George wrote: 1. I think Visual Studio 2008 provides correct result in the sample you provided. Are there anything wrong?
2. Does your sample have anything related to my question?
1. I haven't found where in the ISO C++:2003 states how this issue should be working.
But, remember?! You posted Stroustrup's words in previous thread.
And that quote matches GCC document's statement.
2. Something about name resolution ...
Maxwell Chen
|
|
|
|
|
|
George_George wrote: Seems like Visual Studio is wrong. Please look at section 35.19 of,
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19[^]
1.I think this line of statement matters, agree?
--------------------
the compiler does not look in dependent base classes (like B<t> when looking up nondependent names (like f).
--------------------
This is correct Visual Studio compiles the non-valid code without any troubles
George_George wrote: 2. What disadvantage do we have if the code can compile?
Thats a hard one since Visual Studio compiles and provides the correct solution. Even when there are global variables or function is correctly understand what the programmer wants and does a check the base class first.
This brings us too two other questions one might ask.
1. Can one write code which breaks this rule? Meaning, can on write code that explicit calls the global function instead of the base function?
2. If this is not possible, why does the rule: the compiler does not look in dependent base classes (like B<t> when looking up nondependent names (like f). exist? Is it because older compilers where not smart enough to clear this up?
codito ergo sum
|
|
|
|
|
The intention Stroustrup and the ISO C++ team defined this seems because they hoped to avoid the "nasty macro-like behaviours" (see George's previous thread).
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
I understand what means "nasty macro-like behaviours", but I do not think "nasty macro-like behaviours" is similar to my sample in original question?
regards,
George
|
|
|
|
|
George_George wrote: I understand what means "nasty macro-like behaviours", but I do not think "nasty macro-like behaviours" is similar to my sample in original question?
Your sample in the original question in this thread originated from your previous thread quoting Stroustrup's words. You forgot?!
Maxwell Chen
|
|
|
|
|
Don't push me doing copy-and-paste!!
Maxwell Chen
|
|
|
|
|
What do you mean, Maxwell?
regards,
George
|
|
|
|
|
George_George wrote: What do you mean, Maxwell?
(I am home, so I can copy-and-paste now! )
In the beginning, you quoted Stroustrup's words.
Not can an unqualified name used in a template
ever be bound to a local name. Finally, even if a template
is first used within a class, unqualified names used in the template
will not be bound to members of that class.
Ignoring lcoal names is essential to prevent a lot of
nasty macro-like behavior.
section C.18.3.3 Point of Instantiation Binding
So I gave you that GCC document[^], which introduced this code sample.
Doesn't the code match what Stroustrup said?!
template <typename T>
struct Base {
int i;
};
template <typename T>
struct Derived : public Base<T> {
int get_i() { return i; }
};
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I am interested about your points,
--------------------
Even if a template is first used within a class, unqualified names used in the will not be bound to members of that class.
--------------------
To make discussion clear, could you let me know,
1. what is a template do you refer to in the sample?
2. what is the class (within a class) do you refer to in the sample?
3. what is the unqualified names do you refer to in the sample?
4. what is the "members of that class" do you refere to in the sample?
regards,
George
|
|
|
|
|
George_George wrote: 1. what is a template do you refer to in the sample?
2. what is the class (within a class) do you refer to in the sample?
3. what is the unqualified names do you refer to in the sample?
4. what is the "members of that class" do you refere to in the sample?
1. You saw the keyword template .
2. A struct is a class with members being public by default.
3. That i .
4. That i is the member of the struct (class ).
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I am confused about your points 1 and 2.
I can not believe when Bjarne said "Even if a template is first used within a class", he means even if a template keyword? is first used within a class? It should be some specific template, right?
Should it mean even if template Base<t> first used within a class Derived<t>?
Maxwell Chen wrote: 1. You saw the keyword template.
2. A struct is a class with members being public by default.
regards,
George
|
|
|
|
|
George_George wrote: I can not believe when Bjarne said "Even if a template is first used within a class", he means even if a template keyword? is first used within a class? It should be some specific template, right?
I review the section C.13.8.3 again. I think that the GCC sample fits the first sentence.
Not can an unqualified name used in a template
ever be bound to a local name.
And you were challenging
a template is first used within a class
v.s.
template Base first used within a class Derived ...
Stroustrup's sample code on page 863 in section C.13.8.3 explains the 2nd sentence.
Finally, even if a template is first used within a class,
unqualified names used in the template will
not be bound to members of that class.
template<classT>
void sort(vector<T>& v)
{
sort(v.begin(), v.end());
}
class Container{
vector<int> v;
public:
void sort()
{
sort(v);
}
};
Maxwell Chen
|
|
|
|