little C++ Syntax Problem

P

Pascal Steiss

Hi All

I'm new to C++.
I tried to write the following code:

<-- snip --

#include <cmath>
#include <iostream>

template < class K, class Y >
void NumerovIntegrate ( const K &k2, Y &y0, Y &y1, double &x0, double h,
unsigned int N ) {
<Y> y0_temp;
for (int i=1; i<=N; i++) {
y0_temp = y1;
y1 = 1/(1+h*h/12*sqr(k2(x0+2*h)))*(2*(1-5*h*h/12*sqr(k(x0+h)))*y1-(1
+h*h/12*sqr(k(x0)))*y0);
y0 = y0_temp;
x = x0+h;
}
}

-- snap --

G++ tells me:
-
pascal@thinkpad ~/rgp
$ g++ Numerov.cpp
Numerov.cpp: In function `void NumerovIntegrate(const K&, Y&, Y&,
double&,
double, unsigned int)':
Numerov.cpp:6: error: syntax error before `<' token
-
-
pascal@thinkpad ~/rgp
$ g++ -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld --
with-gnu-
as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--libexe
cdir=/usr/sbin --mandir=/usr/share/man --infodir=/usr/share/info --
enable-langua
ges=c,ada,c++,f77,pascal,java,objc --enable-libgcj --enable-
threads=posix --with
-system-zlib --enable-nls --without-included-gettext --enable-
interpreter --enab
le-sjlj-exceptions --disable-version-specific-runtime-libs --enable-
shared --dis
able-win32-registry --enable-java-gc=boehm --disable-hash-
synchronization --verb
ose --target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin
Thread model: posix
gcc version 3.3.1 (cygming special)
---

Can anyone help me please?

Thanks!
Pascal
 
M

Mike Smith

Pascal said:
Hi All

I'm new to C++.
I tried to write the following code:

<-- snip --

#include <cmath>
#include <iostream>

template < class K, class Y >
void NumerovIntegrate ( const K &k2, Y &y0, Y &y1, double &x0, double h,
unsigned int N ) {
<Y> y0_temp;

There should be no angle brackets in the line above.
 
R

Ron Natalie

Pascal Steiss said:
I'm new to C++.
I tried to write the following code:

Always helpful to us to mark what line ther error message is. Counting
lines is tedious and blank lines tend to come and go in email formatting.

<Y> y0_temp;

I suspect this is the problem.
Y y0_temp;
is what you really want.
 
A

Artie Gold

Pascal said:
Hi All

I'm new to C++.
I tried to write the following code:

<-- snip --

#include <cmath>
#include <iostream>

template < class K, class Y >
void NumerovIntegrate ( const K &k2, Y &y0, Y &y1, double &x0, double h,
unsigned int N ) {
<Y> y0_temp;

ITYM:
Y y0_temp;
for (int i=1; i<=N; i++) {
y0_temp = y1;
y1 = 1/(1+h*h/12*sqr(k2(x0+2*h)))*(2*(1-5*h*h/12*sqr(k(x0+h)))*y1-(1
+h*h/12*sqr(k(x0)))*y0);
y0 = y0_temp;
x = x0+h;
}
}
[snip]

HTH,
--ag
 
P

Pascal Steiss

Mike said:
There should be no angle brackets in the line above.

Sorry for my stupidity - but now G++ tells me
-- snip --

pascal@thinkpad ~/rgp
$ g++ Numerov.cpp
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../libcygwin.a(libcmain.o)
(.text+0x7
c): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status

-- snap --

What does this mean?
Is this a G++_ON_CYGWIN Bug?

Pascal
 
S

Samuele Armondi

Pascal Steiss said:
Sorry for my stupidity - but now G++ tells me
-- snip --

pascal@thinkpad ~/rgp
$ g++ Numerov.cpp
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../libcygwin.a(libcmain.o)
(.text+0x7
c): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status

-- snap --

What does this mean?
Is this a G++_ON_CYGWIN Bug?

Pascal
That is because you created a windows project... set the project type to dos
(console) and create a main function (remember, main returns _int_).
HTH,
S. Armondi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top