473,480 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to make this possible

nik
hello friends, the following code is not running but it replace n by j
& create error i.e. undeclared tokenj . but i want to call
token0,token1 from the loop in main.how it could be achieved.plz tell
me

#include <iostream.h>
#define paster(n) token##n##() //token pasting
int token1() //token1() defination
{
return 1;

}
int token0() //token1() defination
{
return 0;

}
void main( )
{
for(int j=0;j<2;j++) //for Loop for j=0,1
{
int i=paster(j); //to call
token0(),token1()
cout<<"\n"<<i;
}
}

Aug 6 '06 #1
4 1041
nik wrote:
hello friends, the following code is not running but it replace n by j
& create error i.e. undeclared tokenj . but i want to call
token0,token1 from the loop in main.how it could be achieved.plz tell
me
This is not possible. The names are static at compile time and typicall
don't exist anymore at runtime. You want them to be dynamically chosen. The
paster() macro is resolved in the preprocessor, before the actual compiler
even sees the code.
Use a vector of function pointers instead.
#include <iostream.h>
Non-standard header.
#define paster(n) token##n##() //token pasting
int token1() //token1() defination
{
return 1;

}
int token0() //token1() defination
{
return 0;

}
void main( )
main() must return int.
{
for(int j=0;j<2;j++) //for Loop for j=0,1
{
int i=paster(j); //to call
token0(),token1()
cout<<"\n"<<i;
}
}
Aug 6 '06 #2
nik
plz tell me the coding for that
Rolf Magnus wrote:
nik wrote:
hello friends, the following code is not running but it replace n by j
& create error i.e. undeclared tokenj . but i want to call
token0,token1 from the loop in main.how it could be achieved.plz tell
me

This is not possible. The names are static at compile time and typicall
don't exist anymore at runtime. You want them to be dynamically chosen. The
paster() macro is resolved in the preprocessor, before the actual compiler
even sees the code.
Use a vector of function pointers instead.
#include <iostream.h>

Non-standard header.
#define paster(n) token##n##() //token pasting
int token1() //token1() defination
{
return 1;

}
int token0() //token1() defination
{
return 0;

}
void main( )

main() must return int.
{
for(int j=0;j<2;j++) //for Loop for j=0,1
{
int i=paster(j); //to call
token0(),token1()
cout<<"\n"<<i;
}
}
Aug 6 '06 #3
nik wrote:
plz tell me the coding for that
Rolf Magnus wrote:
#include <iostream.h>

Non-standard header.
#define paster(n) token##n##() //token pasting
int token1() //token1() defination
{
return 1;

}
int token0() //token1() defination
{
return 0;

}
void main( )

main() must return int.
{
for(int j=0;j<2;j++) //for Loop for j=0,1
{
int i=paster(j); //to call
token0(),token1()
cout<<"\n"<<i;
}
}

#include <iostream.h>
using namespace std;

int token1() //token1() defination
{
return 1;
}
int token0() //token1() defination
{
return 0;
}

typedef int MyFunction();
MyFunction myfunctions[] = {token0,token1};

int main(){
for(int i = 0;i < 2;++i)
cout << myfuntions[i]() << endl;
}
Aug 6 '06 #4

"Thorsten Kiefer" <th************@gmx.dewrote in message
news:eb**********@news01.versatel.de...
typedef int MyFunction();
That's not correct. You meant to define a function pointer, right I think
it's:

typedef int (*MyFunction)();
MyFunction myfunctions[] = {token0,token1};

int main(){
for(int i = 0;i < 2;++i)
cout << myfuntions[i]() << endl;
typo: myfunctions
}
-Howard

Aug 7 '06 #5

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

Similar topics

12
7118
by: Mike B | last post by:
How do you make it source your source code is unreadable? I went to a website and tried to look at their source, and it came up blank. I then saved the file and got a message saying something...
1
12498
by: amith | last post by:
Hi, I have a javascript, calendar.js which i use to enable my client to select the date. This calendar pops up on the click of a gif image. But the problem is that this poped up window is not...
3
2469
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
4
1182
by: foodic | last post by:
I am new to make file concepts. All I need to know whether Is it possible to extract missing directories in the source while executing make -n?For example missing text-utils directory in my...
2
3782
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
3
1023
by: steve | last post by:
Hi I've been wondering for a wile now if its possible to make an application were the user can make a form by inputting data in variables this by using VB.net Example The user gets a dataset...
8
3236
by: Scott Emick | last post by:
I am using the following to compute distances between two lat/long coordinates for a store locator - (VB .NET 2003) it seems to take a long time to iterate through like 100-150 locations -...
28
2904
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
2671
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
10
2413
by: AA Arens | last post by:
I do have a database with customer info in it. To avoid it will be taken out of our office, is it possible to make it not-readable after a certain period? then every let say seven days, I needs to...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.