473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Template instantiation problem with vc++.net 7.1 compiler

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
5 2316

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
10
by: philchen1978 | last post by:
Hi, I can compile the code below with GCC 3.4.2, because function g is a "dependent name". template<class T> void f1(T t) { g(t); }
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
5
by: merdem | last post by:
Hi all, I am not sure if this post is more appropriate for comp.lan.learn.c++. My apologies if it is. I am at a loss with my template class. It is something like this (pruned for space): ...
5
by: Wayne Shu | last post by:
Hi, guys I am reading Vandevoorde and Josuttis 's "C++ Template The Complete Guide" these days. When I read the chapter 15: Traits and Policy classes. I copy the code in 15.2.2 that use to...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.