By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

Template instantiation problem with vc++.net 7.1 compiler

P: n/a
Guys please help me to solve this strange problem what Iam
getting as follows..

Trying to instantiate a global instance of a template
class as follows :-

when i build this code with debug and run this works fine.
but if build in unicode release or release this does't
work.
IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
RELEASE ??????
( this is only happening with visual studio .net compiler
version 7.1. I have tried with vc++ 6.0 this works fine)

class a
{
public:
a() {}
};
// specialize constructor with a dummy class
class dummy
{
};
template <class T> class tc
{
public:
tc(const dummy&)
{
MessageBox(NULL, _T("template with dummy Got
constructed..."), _T(""), MB_OK);
}
private:
const static tc<T>* ptc; // Initialize when this
classs constructs
};
// construct a global templete object here
const tc<a>* tc<a>::ptc = new tc<a>(dummy());
int main(int argc, char* argv[])
{
return 0;
}

Thanks in advance guys
Hari
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Hari" <pp****@hotmail.com> skrev i meddelandet
news:06****************************@phx.gbl...
Guys please help me to solve this strange problem what Iam
getting as follows..

Trying to instantiate a global instance of a template
class as follows :-

when i build this code with debug and run this works fine.
but if build in unicode release or release this does't
work.
IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
RELEASE ??????


You mean instantiating objects that are never referenced, so that the
linker doesn't include them in the .exe file?
Nov 16 '05 #2

P: n/a
Hello Hari,

Thanks for your post.

It seems that MessageBox is not being referenced in the default setting.
Please change the Link Optimizations Option: /OPT:REF(default) to /OPT:NOREF

To do this, firstly please select the "Properties" of your application in
the Solution Explorer Window, then in the Property Pages window, change the
"Configurations:" to "Release", and navigate to
"Configuration/Linker/Optimization" in the left treeview control. Now you
can select "References" to "Keep Unreferenced Data (/OPT:NOREF)" in the
right frame, finally click "OK" to apply this setting.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Hari" <pp****@hotmail.com>
!Sender: "Hari" <pp****@hotmail.com>
!Subject: Template instantiation problem with vc++.net 7.1 compiler
!Date: Thu, 25 Sep 2003 10:23:42 -0700
!Lines: 45
!Message-ID: <06****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcODicSHD1JrYWBPRlaLeH3aYsUvGA==
!Newsgroups: microsoft.public.dotnet.languages.vc
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28743
!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Guys please help me to solve this strange problem what Iam
!getting as follows..
!
!Trying to instantiate a global instance of a template
!class as follows :-
!
!when i build this code with debug and run this works fine.
!but if build in unicode release or release this does't
!work.
!IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
!GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
!RELEASE ??????
!( this is only happening with visual studio .net compiler
!version 7.1. I have tried with vc++ 6.0 this works fine)
!
!class a
!{
!public:
! a() {}
!};
!// specialize constructor with a dummy class
!class dummy
!{
!};
!template <class T> class tc
!{
!public:
! tc(const dummy&)
! {
! MessageBox(NULL, _T("template with dummy Got
!constructed..."), _T(""), MB_OK);
! }
!private:
! const static tc<T>* ptc; // Initialize when this
!classs constructs
!};
!// construct a global templete object here
!const tc<a>* tc<a>::ptc = new tc<a>(dummy());
!int main(int argc, char* argv[])
!{
! return 0;
!}
!
!Thanks in advance guys
!Hari
!

Nov 16 '05 #3

P: n/a
Dear Yanhong Huang,

Thanks for your help, it works fine with my this my test
app, if I change the linker settings to the /OPT:NOREF. If
I do so it will apply for the whole application and there
won'nt be any optimization happening in my relase build,
please correct me this?

Also I would like to get some information in my real
implementation. Iam using this global instance of this
template for cloning new objects of this same class type,
using a classfactory template. As per your answer if this
global object is being referenced( I need more info on
this, as my understanding the refernce is , if use this
object somewhere else the compiler should recognize it,
please correct me with my statement) somewhere else the
compiler should create an instance in this case?

Please give me more information on this, if you required
more details of this i can send to you..

Thanks
Hari
-----Original Message-----
Hello Hari,

Thanks for your post.

It seems that MessageBox is not being referenced in the default setting.Please change the Link Optimizations Option: /OPT:REF (default) to /OPT:NOREF
To do this, firstly please select the "Properties" of your application inthe Solution Explorer Window, then in the Property Pages window, change the"Configurations:" to "Release", and navigate to
"Configuration/Linker/Optimization" in the left treeview control. Now youcan select "References" to "Keep Unreferenced Data (/OPT:NOREF)" in theright frame, finally click "OK" to apply this setting.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Content-Class: urn:content-classes:message
!From: "Hari" <pp****@hotmail.com>
!Sender: "Hari" <pp****@hotmail.com>
!Subject: Template instantiation problem with vc++.net 7.1 compiler!Date: Thu, 25 Sep 2003 10:23:42 -0700
!Lines: 45
!Message-ID: <06****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcODicSHD1JrYWBPRlaLeH3aYsUvGA==
!Newsgroups: microsoft.public.dotnet.languages.vc
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28743!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Guys please help me to solve this strange problem what Iam!getting as follows..
!
!Trying to instantiate a global instance of a template
!class as follows :-
!
!when i build this code with debug and run this works fine.!but if build in unicode release or release this does't
!work.
!IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
!GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
!RELEASE ??????
!( this is only happening with visual studio .net compiler!version 7.1. I have tried with vc++ 6.0 this works fine)
!
!class a
!{
!public:
! a() {}
!};
!// specialize constructor with a dummy class
!class dummy
!{
!};
!template <class T> class tc
!{
!public:
! tc(const dummy&)
! {
! MessageBox(NULL, _T("template with dummy Got
!constructed..."), _T(""), MB_OK);
! }
!private:
! const static tc<T>* ptc; // Initialize when this
!classs constructs
!};
!// construct a global templete object here
!const tc<a>* tc<a>::ptc = new tc<a>(dummy());
!int main(int argc, char* argv[])
!{
! return 0;
!}
!
!Thanks in advance guys
!Hari
!

.

Nov 16 '05 #4

P: n/a
Hello Hari,

Thanks for the response.

1) Yes, the setting is applied to the whole project. However, it doesn't
mean that the release build wont' have any optimization. Since there are
many optimization settings in vs.net. It just closes one setting.

2) I have not totally understand your question. Accroding to my
understanding, you have created an instance of this template class
globally. The MessageBox call is in its constructor. So it is called when
the program executes.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Hari" <pp****@hotmail.com>
!Sender: "Hari" <pp****@hotmail.com>
!References: <06****************************@phx.gbl>
<o6**************@cpmsftngxa06.phx.gbl>
!Subject: RE: Template instantiation problem with vc++.net 7.1 compiler
!Date: Fri, 26 Sep 2003 10:22:23 -0700
!Lines: 132
!Message-ID: <15****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcOEUr+neMeIxWN3S3SxP63CoRMJQA==
!Newsgroups: microsoft.public.dotnet.languages.vc
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28782
!NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Dear Yanhong Huang,
!
!Thanks for your help, it works fine with my this my test
!app, if I change the linker settings to the /OPT:NOREF. If
!I do so it will apply for the whole application and there
!won'nt be any optimization happening in my relase build,
!please correct me this?
!
!Also I would like to get some information in my real
!implementation. Iam using this global instance of this
!template for cloning new objects of this same class type,
!using a classfactory template. As per your answer if this
!global object is being referenced( I need more info on
!this, as my understanding the refernce is , if use this
!object somewhere else the compiler should recognize it,
!please correct me with my statement) somewhere else the
!compiler should create an instance in this case?
!
!Please give me more information on this, if you required
!more details of this i can send to you..
!
!Thanks
!Hari
!
!
!
!>-----Original Message-----
!>Hello Hari,
!>
!>Thanks for your post.
!>
!>It seems that MessageBox is not being referenced in the
!default setting.
!>Please change the Link Optimizations Option: /OPT:REF
!(default) to /OPT:NOREF
!>
!>To do this, firstly please select the "Properties" of
!your application in
!>the Solution Explorer Window, then in the Property Pages
!window, change the
!>"Configurations:" to "Release", and navigate to
!>"Configuration/Linker/Optimization" in the left treeview
!control. Now you
!>can select "References" to "Keep Unreferenced Data
!(/OPT:NOREF)" in the
!>right frame, finally click "OK" to apply this setting.
!>
!>Hope that helps.
!>
!>Best regards,
!>Yanhong Huang
!>Microsoft Online Partner Support
!>
!>Get Secure! - www.microsoft.com/security
!>This posting is provided "AS IS" with no warranties, and
!confers no rights.
!>
!>--------------------
!>!Content-Class: urn:content-classes:message
!>!From: "Hari" <pp****@hotmail.com>
!>!Sender: "Hari" <pp****@hotmail.com>
!>!Subject: Template instantiation problem with vc++.net
!7.1 compiler
!>!Date: Thu, 25 Sep 2003 10:23:42 -0700
!>!Lines: 45
!>!Message-ID: <06****************************@phx.gbl>
!>!MIME-Version: 1.0
!>!Content-Type: text/plain;
!>! charset="iso-8859-1"
!>!Content-Transfer-Encoding: 7bit
!>!X-Newsreader: Microsoft CDO for Windows 2000
!>!X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!>!Thread-Index: AcODicSHD1JrYWBPRlaLeH3aYsUvGA==
!>!Newsgroups: microsoft.public.dotnet.languages.vc
!>!Path: cpmsftngxa06.phx.gbl
!>!Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.languages.vc:28743
!>!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!>!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!>!
!>!Guys please help me to solve this strange problem what
!Iam
!>!getting as follows..
!>!
!>!Trying to instantiate a global instance of a template
!>!class as follows :-
!>!
!>!when i build this code with debug and run this works
!fine.
!>!but if build in unicode release or release this does't
!>!work.
!>!IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
!>!GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
!>!RELEASE ??????
!>!( this is only happening with visual studio .net
!compiler
!>!version 7.1. I have tried with vc++ 6.0 this works fine)
!>!
!>!class a
!>!{
!>!public:
!>! a() {}
!>!};
!>!// specialize constructor with a dummy class
!>!class dummy
!>!{
!>!};
!>!template <class T> class tc
!>!{
!>!public:
!>! tc(const dummy&)
!>! {
!>! MessageBox(NULL, _T("template with dummy Got
!>!constructed..."), _T(""), MB_OK);
!>! }
!>!private:
!>! const static tc<T>* ptc; // Initialize when this
!>!classs constructs
!>!};
!>!// construct a global templete object here
!>!const tc<a>* tc<a>::ptc = new tc<a>(dummy());
!>!int main(int argc, char* argv[])
!>!{
!>! return 0;
!>!}
!>!
!>!Thanks in advance guys
!>!Hari
!>!
!>
!>.
!>
!

Nov 16 '05 #5

P: n/a
Hello Hari,

Thanks for the response.

1) Yes, the setting is applied to the whole project. However, it doesn't
mean that the release build wont' have any optimization. Since there are
many optimization settings in vs.net. It just closes one setting.

2) I have not totally understand your question. Accroding to my
understanding, you have created an instance of this template class
globally. The MessageBox call is in its constructor. So it is called when
the program executes.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Hari" <pp****@hotmail.com>
!Sender: "Hari" <pp****@hotmail.com>
!References: <06****************************@phx.gbl>
<o6**************@cpmsftngxa06.phx.gbl>
!Subject: RE: Template instantiation problem with vc++.net 7.1 compiler
!Date: Fri, 26 Sep 2003 10:22:23 -0700
!Lines: 132
!Message-ID: <15****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcOEUr+neMeIxWN3S3SxP63CoRMJQA==
!Newsgroups: microsoft.public.dotnet.languages.vc
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28782
!NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Dear Yanhong Huang,
!
!Thanks for your help, it works fine with my this my test
!app, if I change the linker settings to the /OPT:NOREF. If
!I do so it will apply for the whole application and there
!won'nt be any optimization happening in my relase build,
!please correct me this?
!
!Also I would like to get some information in my real
!implementation. Iam using this global instance of this
!template for cloning new objects of this same class type,
!using a classfactory template. As per your answer if this
!global object is being referenced( I need more info on
!this, as my understanding the refernce is , if use this
!object somewhere else the compiler should recognize it,
!please correct me with my statement) somewhere else the
!compiler should create an instance in this case?
!
!Please give me more information on this, if you required
!more details of this i can send to you..
!
!Thanks
!Hari
!
!
!
!>-----Original Message-----
!>Hello Hari,
!>
!>Thanks for your post.
!>
!>It seems that MessageBox is not being referenced in the
!default setting.
!>Please change the Link Optimizations Option: /OPT:REF
!(default) to /OPT:NOREF
!>
!>To do this, firstly please select the "Properties" of
!your application in
!>the Solution Explorer Window, then in the Property Pages
!window, change the
!>"Configurations:" to "Release", and navigate to
!>"Configuration/Linker/Optimization" in the left treeview
!control. Now you
!>can select "References" to "Keep Unreferenced Data
!(/OPT:NOREF)" in the
!>right frame, finally click "OK" to apply this setting.
!>
!>Hope that helps.
!>
!>Best regards,
!>Yanhong Huang
!>Microsoft Online Partner Support
!>
!>Get Secure! - www.microsoft.com/security
!>This posting is provided "AS IS" with no warranties, and
!confers no rights.
!>
!>--------------------
!>!Content-Class: urn:content-classes:message
!>!From: "Hari" <pp****@hotmail.com>
!>!Sender: "Hari" <pp****@hotmail.com>
!>!Subject: Template instantiation problem with vc++.net
!7.1 compiler
!>!Date: Thu, 25 Sep 2003 10:23:42 -0700
!>!Lines: 45
!>!Message-ID: <06****************************@phx.gbl>
!>!MIME-Version: 1.0
!>!Content-Type: text/plain;
!>! charset="iso-8859-1"
!>!Content-Transfer-Encoding: 7bit
!>!X-Newsreader: Microsoft CDO for Windows 2000
!>!X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!>!Thread-Index: AcODicSHD1JrYWBPRlaLeH3aYsUvGA==
!>!Newsgroups: microsoft.public.dotnet.languages.vc
!>!Path: cpmsftngxa06.phx.gbl
!>!Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.languages.vc:28743
!>!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!>!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!>!
!>!Guys please help me to solve this strange problem what
!Iam
!>!getting as follows..
!>!
!>!Trying to instantiate a global instance of a template
!>!class as follows :-
!>!
!>!when i build this code with debug and run this works
!fine.
!>!but if build in unicode release or release this does't
!>!work.
!>!IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
!>!GLOBALY IN APPLICATION BUILD WITH UNICODE RELEASE OR
!>!RELEASE ??????
!>!( this is only happening with visual studio .net
!compiler
!>!version 7.1. I have tried with vc++ 6.0 this works fine)
!>!
!>!class a
!>!{
!>!public:
!>! a() {}
!>!};
!>!// specialize constructor with a dummy class
!>!class dummy
!>!{
!>!};
!>!template <class T> class tc
!>!{
!>!public:
!>! tc(const dummy&)
!>! {
!>! MessageBox(NULL, _T("template with dummy Got
!>!constructed..."), _T(""), MB_OK);
!>! }
!>!private:
!>! const static tc<T>* ptc; // Initialize when this
!>!classs constructs
!>!};
!>!// construct a global templete object here
!>!const tc<a>* tc<a>::ptc = new tc<a>(dummy());
!>!int main(int argc, char* argv[])
!>!{
!>! return 0;
!>!}
!>!
!>!Thanks in advance guys
!>!Hari
!>!
!>
!>.
!>
!

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.