|
hi,
i am opening a binary file in visual studio2005.so the file will be the active window.when i click the addin in tool menu i have to take the binary file as input.
if any one knows about this please give me the code .
pmr
|
|
|
|
|
Hi,
I m using CColorDialog to display the color pallete dialog in my project.
its working fine..
but i wan my dialogs to be updated with the color selected by the color selected by the user in tat CColorDialog.
I m using SetCurrentColor().But the color s not updated in the dialog..
how to achieve tis..
suggestions reqd..
My snippet follows:
[ color c;
CColorDialog dlg;
dlg.m_cc.Flags |= CC_FULLOPEN | CC_RGBINIT;
dlg.m_cc.rgbResult = RGB(155, 0, 0);
dlg.DoModal();
c.SetCurrentColor(RGB(155, 0, 0));
c.DoModal(); ]
Gita
|
|
|
|
|
color c; // is this a derived class from CColorDialog ?
c.SetCurrentColor(RGB(155, 0, 0));
c.DoModal();
"Call this function after calling DoModal to force the current color selection to the color value specified in clr." from msdn.
This function is called from within a message handler.
if you want before DoModal, you can do similar to dlg.m_cc.rgbResult = RGB(155, 0, 0);
|
|
|
|
|
Hello everyone,
For the following code from Bjarne's book, it is stated that template parameter T for function g will be instantised as int other than double. My question is why there are not two instantiations for both int and double version of template function g?
template <class T> void f (T a) { g(a); }
void g(int);
void h()
{
extern g (double);
f (2);
}
Here is the related statement from Bjarne,
--------------------
Each use of a template for a given set of template arguments defines a point of instantiation.
That point is the nearest global or namespace scope enclosing its use,
just before the declaration that contains that use.
--------------------
Does it before g (double) is not global function or namespace scope enclosing its use? If yes, I do not know why g (double) is not a global function, since it is declared as extern and some other compile unit should expose it?
thanks in advance,
George
|
|
|
|
|
Simply I cannot understand you point: you're calling f(2) , i.e. template function with int argument. It is quite obvious that compiler will instantiate only the int specialization of the template function.
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
|
|
|
|
|
Hi CPallini,
Why statement extern g (double); will not instantise a double version f, i.e. f (double)?
regards,
George
|
|
|
|
|
And why should it do? The template function is f , not g .
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
|
|
|
|
|
Hi CPallini,
Bjarne's point, void g(int) statement will instantise
template <class T> void f (T a) { g(a); }
by deducing the type of T int, since in g(a), type of a is T and we are declaring g(int).
My question is why extern g(double) does not have the same effect to deduct parameter T to double?
regards,
George
|
|
|
|
|
OK, things are more clear, at least to me, changing the sample into
template <class t=""> void f (T a) { g(a); }
void g(int x) { return;}
void h()
{
extern void g (double);
f (2.5);
}
</class>
I made a test (defining void g (double) ) into another source file. The result was that only int specialization of f was built by the compiler, confirming Bjarne point.
Now, while it is clear that g(double) is exposed by correnponding source file, maybe that its declaration make it scoped only into h() i.e. local.
I have to admit the point it is not so clear.
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
|
|
|
|
|
Hi CPallini,
Thanks for your reply. Do you have any effective and efficient ways to debug template function to find out the type of template parameters?
regards,
George
|
|
|
|
|
George_George wrote: extern g (double);
extern is a sort of forward declaration... it doesn't define a g(double) function at all.
and if anywhere in your code, such a function exist, the only function to get called will be g(int) (because it's the only one which actually exist...)
|
|
|
|
|
Hi toxcct,
Sorry I do not agree with you. Please look at Rajkumar's reply which proves what matters is whether declaration is local or global, what not matters is whether using extern or whether a definition or delaration. I think both definition and declaration can make an instantiation.
Any comments? Please feel free to correct me if I am wrong.
regards,
George
|
|
|
|
|
George_George wrote: f (2);
Are you missing here something like f<double> (2); or f(2.0); ?
George_George wrote: Does it before g (double) is not global function or namespace scope enclosing its use? If yes, I do not know why g (double) is not a global function, since it is declared as extern and some other compile unit should expose it?
yes, the definition of the g(double) must be in global scope of some other compilation unit to specify the linkage specifier extern. but its declaration is not in global scope or namespace scope at the point of function template instantiation for 'void f<double>(T)' being compiled.
In your sample declaration is in function scope of h();
try this,
template <class T>
void f (T a)
{ g(a);
}
void g(int);
extern g (double);
void h()
{
f <double>(2);
}
|
|
|
|
|
Cool, Rajkumar!
1.
I think the original code does not work is because declaration of using g is local? Confirms to Bjarne'e comments -- "global or namespace scope enclosing its use, just before the declaration that contains that use"? Important points are global and declaration. Right?
--------------------
Each use of a template for a given set of template arguments defines a point of instantiation.
That point is the nearest global or namespace scope enclosing its use,
just before the declaration that contains that use.
--------------------
2.
You like explicitly assign parameter for template function, like f<double>(2), other than f(2). Is it for the good of reducing ambiguity? Any other benefits?
regards,
George
|
|
|
|
|
George_George wrote: Important points are global and declaration. Right?
yes.
George_George wrote: You like explicitly assign parameter for template function, like f <double>(2), other than f(2).
in your argument you want to deduce double but you specified f(2) not f(2.0), if you have this tendency always go for explicit deducing template function like f<double>(2);
|
|
|
|
|
|
George_George wrote: I think both declaration and definition can instantise the template function, right?
actually consider declaration, definition implicitly has declaration. if it is inline function, definition should be in the scope at the point of intantiation.
|
|
|
|
|
Thanks Rajkumar,
Your reply is clear. Definition (which is also declaration implicitly) and declaration both will trigger instantiation.
regards,
George
|
|
|
|
|
Hi Rajkumar,
I have a further question. I have tried similar code as yours. But can not compile in Visual Studio 2008. Any ideas? f<int> (100) works. Why?
BTW: a fix of
1>d:\visual studio 2008\projects\test_template3\test_template3\main.cpp(16) : error C2783: 'void f(int)' : could not deduce template argument for 'T'
1> d:\visual studio 2008\projects\test_template3\test_template3\main.cpp(5) : see declaration of 'f'
#include <iostream>
using namespace std;
template <class T> void f(int a) {g (a);}
void g(int a)
{
cout << a << endl;
}
extern void g(double);
int main()
{
f (100);
return 0;
}
regards,
George
|
|
|
|
|
George_George wrote: I have tried similar code as yours
it is not at all similar.
in my example it is
template <class T> void f(T a) {g (a);}
template <class T> void f(int a) {g (a);} in this Template argument T is not addressed, in this case you want call like,
f<char> (100); // i used char just to deduce T.
similarly
template <class T1, class T2> void f(T2 a) {g (a);} here also template argument T1 is not deduced. here also you can use f<char> (100);
if you want template specialization, use like this,
void g(int a)
{ cout << a << endl;
}
extern void g(double);
template <class T>
void f(T a)
{
g (a);
}
<code>template <>
void f(int a)
{
g (a);
}
or
template <>
void f <int>(int a)
{
g (a);
}</code>
int main()
{
f (100);
return 0;
}
modified on Thursday, March 6, 2008 7:20 AM
|
|
|
|
|
Thanks Rajkumar,
I have tried if we remove the following two functions, it still works. Seems the two specializations are useless? Any comments?
template <> void f(int a) { g (a);}
template <> void f <int>(int a) { g (a);}
regards,
George
|
|
|
|
|
that are examples. when i found your examples of "template<class T> void f(int a)", i just given example if you meant specialisation.
George_George wrote: I have tried if we remove the following two functions
because you have generic functions with template argument T already.
George_George wrote: Seems the two specializations are useless?
It is useful if you write special code apart from generic function in the template specialization.
|
|
|
|
|
Thanks Rajkumar!
template <> void f(int a) { g (a);}
template <> void f <int>(int a) { g (a);}
Are the two above function definitons of the same function and just different coding style? Or they have differences?
regards,
George
|
|
|
|
|
I think both are same explicit specialization as if you define both, induce redefinition error, literally, the former template argument is deduced while the later template argument is specified.
|
|
|
|
|
Thanks Rajkumar,
I have got the redefinition error as you pointed out. Cool! But to use the latter one, it is also not mandatory needed to specify the template parameter type, it could also be deduced. Here is my code to prove. Any comments?
#include <iostream>
using namespace std;
void g(int a){ cout << a << endl;}
template <class T> void f(T a) { g (a);}
template <> void f <int>(int a) { g (a);}
int main()
{
f (100);
return 0;
}
regards,
George
|
|
|
|