I tried using #pragma optimize("", off) to selectively disable optimizations for the a() function. This does not work. Is there any way to control optimization of a template function in visual studio c 2017?
Header.h
#pragma once
#include <iostream>
using namespace std;
template <class T>
class my
{
public:
void f();
};
#pragma optimize("", off)
template<class T>
void my<T>::f()
{
double a = 0;
for (size_t i = 0; i < 100; i )
{
a ;
}
cout << a;
}
#pragma optimize("", on)
Header.cpp
#include <iostream>
#include <vector>
#include "Header.h"
using namespace std;
int main()
{
my<string> a;
a.f();
return 0;
system("pause");
}
CodePudding user response:
This problem has been raised in Developer Community. This question has not been updated yet, it needs to wait.
CodePudding user response:
There is a indirect method in Developer Community. https://developercommunity.visualstudio.com/t/no-way-to-control-optimization-of-a-template-funct/104899