|
Thanks CPallini,
Then could I understand in my original sample, there are actually 4 classes (without name decoration)?
- Foo;
- Goo;
- Abc < Foo >;
- Abc < Goo >;
regards,
George
|
|
|
|
|
What I think is 'class T' in the template is used as a Data Type declaration, and not just the pre compile replacements (as you expected Abc : Foo or Abc : Goo). So, you can use the T for member variable declarations in the class Abc, and not for the inheritance.
Compiler does replace the 'T' in the template, except the part of the template or class definition. So, you'd never find as 'Abc : Foo' or 'Abc : Goo'. This may help you.
- Malli...!
|
|
|
|
|
Thanks Malli_S,
I think template expansion is happening at compile time. After template expansion, what are the final classes?
regards,
George
|
|
|
|
|
You're right George, template expansions are done are compile time. I was just giving you thought that it's not just the replacement. The template instantiations are done when compiler comes across the class template's object declaration. In case of
template <class t="">
class Abc
{
T m_iVariable;
...
};
int main()
{
...
Abc <int> objInt;
Abc <double> objDouble;
...
Abc <int> objInt2;
}</int></double></int></class>
when the compiler comes across the statements
Abc <int> objInt;
Abc <double> objDouble;</double></int>
it generates the code for respective data types, which is called as template instantiating. These instants (generated code) persists through you program within it's scope. i.e. no more template instance is generated for 'objInt2' as the 'int' version of the template is already in exist.
- Malli...!
|
|
|
|
|
In my sample,
Abc < Foo >
will be expanded to
Abc:Foo
And
Abc < Goo >
will be expanded to
Abc:Goo
So, class Abc will be defined twice. So I think there is conflicting. Any ideas or comments?
regards,
George
|
|
|
|
|
I think template class names will be name mangled
Regards,
Sandip.
|
|
|
|
|
What do you think will be the classes' after template instantiation/expansion, Sandip?
regards,
George
|
|
|
|
|
Hi George,
I am not sure exactly what will be the class names. I even dont know any way through which you can see the class names after expansion.
I tried
class Foo: public CObject
{
public:
int add(int a , int b)
{
return a+b;
}
};
class Goo : public CObject
{
public:
int add(int a , int b)
{
return a+b;
}
};
template <class t="">
class Abc : public T
{
};
</class>
I used CObject because this enables my class to have RTTI.
now when i step in the respective add functions i see following contents in the watch window
this VFoo::?$abc
this VGoo::?$abc
Regards,
Sandip.
|
|
|
|
|
Thanks Sandip,
So in your sample, actually there will be two classes Abc < Foo > and Abc < Goo > , other than a single Abc class?
regards,
George
|
|
|
|
|
George_George wrote: So in your sample, actually there will be two classes Abc < Foo > and Abc < Goo >
Yes there will be two classes
George_George wrote: other than a single Abc class?
I doubt that this will be there
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
You mentioned in your experiment, you watched window likes this,
this VFoo::?$abc
this VGoo::?$abc
My question is what variable/object are you watching on to get such results?
regards,
George
|
|
|
|
|
i called function add and when i step in to add function
in watch window i see the above values against this pointer.
Regards,
Sandip.
|
|
|
|
|
Thanks Sandip,
You mean you step into the member function like foo and watch for "this" pointer?
regards,
George
|
|
|
|
|
George_George wrote: You mean you step into the member function like foo and watch for "this" pointer?
Yes..
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
I have tried but can not see the same thing.
Here is my situation. Do you know what is the problem?
when I watch this in function Foo::func, the Name/Value/Type in Watch window is
this 0x0012ff63 Foo * const
Here is the code I am using,
class Foo
{
public:
int func();
};
int Foo::func()
{
int a = 3;
return a;
}
class Goo
{
public:
int func();
};
int Goo::func()
{
int a = 3;
return a;
}
template < class T >
class Abc : public T
{
};
int main()
{
Abc < Foo > f;
Abc < Goo > g;
f.func();
g.func();
return 0;
}
regards,
George
|
|
|
|
|
Hi George,
That is because your class does not have RTTI.
That is the reason i derived my classes from CObject.
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
I think RTTI is the capability of runtime to discover the actual underlying type of variable pointed by some pointer. So, in short RTTI is some specific capability of runtime. What do you mean class does not have RTTI? Looks like you think RTTI is some capability of a class? Could you clarify please?
regards,
George
|
|
|
|
|
George_George wrote: So, in short RTTI is some specific capability of runtime.
and in MFC this is supported by CObject.
If you do not derive class using CObject it will not support RTTI.
In my application if i remove CObject it just gives me address just like you.
Does it help..
Regards,
Sandip.
modified on Monday, September 22, 2008 8:07 AM
|
|
|
|
|
Thanks Sandip!
I am not using MFC, any ways to display things like you showed below in a standard C++ project in VC?
this VFoo::?$abc
this VGoo::?$abc
regards,
George
|
|
|
|
|
Now I'm also pretty much sure (after having tested) that templates are name mangled. If you try to use extern 'c' for templates (class/functions), the compilier will flash an error saying 'error C2894: templates cannot be declared to have 'C' linkage'.
- Malli...!
|
|
|
|
|
Are there any ways to see the classes' after template instantiation/expansion, Malli_S?
regards,
George
|
|
|
|
|
I get this message when I run my application which is built on another computer:
This application failed to start because the application initializtion is incorrect.
?????
What?
|
|
|
|
|
Did you use VC2005 ? If yes, you have to download and install vcredist_x86.exe[^] on the target machine. This will install the MFC and C-runtime libraries. If you have installed the SP1 for VC, check at the bottom of the page for the SP1 version of VCredist_x86.
|
|
|
|
|
When right click my tray icon, show the menu, And there is a menu item "Restore window".
When click this menu item, it should restore window.
My code implement "Restore window" below:
void CWinSearchDlg::OnTrayRestoreWnd()
{
DestroyTray();
ShowWindow(SW_SHOW);
<font color="red">
::BringWindowToTop(this->GetSafeHwnd());
::SetForegroundWindow(this->GetSafeHwnd());
::SetActiveWindow(this->GetSafeHwnd());</font>
}
I've tried the code in red font, but when restore the window, It doesn't bring to the top.
Please give me a sign!
|
|
|
|
|
Try using CWnd::SetWindowPos
|
|
|
|