Jump to content


Template member-function instantiation


3 replies to this topic

#1 m1cky

    New Member

  • Members
  • Pip
  • 2 posts

Posted 11 February 2005 - 12:36 PM

Hello,
we have a template problem while upgrading from VC6 to VC7.

Normally only used member functions of a template are instantiated (compiled).
For example if there is a template class which has 3 methods, but only 2 of them are used in my code the third function is not evaluated/compiled.
This seems to work with VC7 as well as with VC6.

Well, if i compile our software i get an error cause the compiler instantiates one method of std::list which it should not compile !
This can have 2 reasons:

- That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

- Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

#2 bladder

    DevMaster Staff

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 11 February 2005 - 01:10 PM

The only times I've heard of code that could compile with vc6 and not vc7 was code that was non standard compliant. What piece of code is refusing to compile in vc7, there has to be some way to re-write it so that it would compile.

Also, just to check. Full optimization is done in release builds. Try compiling in that and see if it works out. You may also want to try fiddeling with the optimization options in teh project settings.

#3 AM_

    New Member

  • Members
  • Pip
  • 4 posts

Posted 11 February 2005 - 01:55 PM

m1cky said:

- That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

- Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

View Post

Yes the compiler checks all code ... also if it's unused.

Are you using your own stl version (stlport) ?

#4 m1cky

    New Member

  • Members
  • Pip
  • 2 posts

Posted 11 February 2005 - 07:04 PM

AM_ said:

m1cky said:

- That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

- Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

View Post

Yes the compiler checks all code ... also if it's unused.

Are you using your own stl version (stlport) ?

View Post



no the compiler dont check all code.
Try this:

class A
{
public:
A(int) {}
};

template <typename T> class B
{
public:
B() {}

void instantiateA() {
T t;
}
};

int main()
{
B<A> b;
}


if you dont call instantiateA in the main u dont get an error message that A provides no default constructor.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users