473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

why this code does not work

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;
}
Jul 19 '05 #1
3 1622
baobaoba wrote:
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.
#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;
}


Jul 19 '05 #2
baobaoba wrote:
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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #3
Kevin Goodsell wrote:
$ 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

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Spam Bill Gates | last post by:
I am using linux, php and trying to do some ssl code. I want to send some identifier that connects my database to the client browser. I was looking into a secure cookie. I only want the page...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
192
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
239
by: Eigenvector | last post by:
My question is more generic, but it involves what I consider ANSI standard C and portability. I happen to be a system admin for multiple platforms and as such a lot of the applications that my...
10
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.