why this code does not work

B

baobaoba

The following code compiles on gcc, but cannot be executed. I got some
wierd message when executed:
1: Syntax error: ")" unexpected

Is there anything wrong in my function template?


#include <iostream>
using namespace std;

class DDComparePolicy
{
public:
static void Compare ()
{
cout<<"DDComparePolicy "<<endl;
}
};

class TDComparePolicy
{
public:
static void Compare ()
{
cout<<"TDComparePolicy "<<endl;
}
};

template <typename Policy>
void validateField()
{
Policy::Compare ();
}

template <typename Policy>
void validateAllFields()
{
validateField<Policy> ();
}

int main ()
{
string currentRecType ="A";
string lastRecType = "A";

if(currentRecType == "A" && lastRecType == "A")
validateAllFields<DDComparePolicy>();
else if(currentRecType == "T" && lastRecType == "A")
validateAllFields<TDComparePolicy>();

return 0;
}
 
B

Buster Copley

baobaoba said:
The following code compiles on gcc, but cannot be executed. I got some
wierd message when executed:
1: Syntax error: ")" unexpected

That is weird.

[buster@localhost scratch]$ g++ -o scratch funct_templ.cpp
[buster@localhost scratch]$ ./scratch
DDComparePolicy
[buster@localhost scratch]$

Seems OK.
Is there anything wrong in my function template?

Hard to say. I hope you can work it out.

Regards,
Buster.
 
K

Kevin Goodsell

baobaoba said:
The following code compiles on gcc, but cannot be executed. I got some
wierd message when executed:
1: Syntax error: ")" unexpected

Is there anything wrong in my function template?

The only thing I see wrong is the lack of a #include <string> directive.

My guess is that you are on a Unix system, and you are invoking the
program incorrectly and running a completely different program instead.
For example, people often name a program 'test' and try to run it:

$ test

Instead of

$ ./test

These two commands refer to completely different programs (depending on
path settings). The first invokes the standard unix 'test' program, the
second invokes the 'test' program that is in the current directory.

-Kevin
 
N

Noah Roberts

Kevin said:
$ test

Instead of

$ ./test

These two commands refer to completely different programs (depending on
path settings). The first invokes the standard unix 'test' program, the
second invokes the 'test' program that is in the current directory.

And what is really funny is that when you do this there is absolutely no
output from what you can see. The system 'test' program simply returns
a value, it doesn't output anything. So you sometimes mistake no output
for something not being executed in your code - and you would be
right...that something is your code, it isn't being executed :p

I myself have been caught by this before, and still accidentally do it
from time to time though I am much faster at catching my error now :p

NR
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top