Solved

subclass versus typedef/#define

Posted on 1998-06-29
7
265 Views
Last Modified: 2011-09-20
A long question,  but I think needs only a shorter answer:

I have a subclass with several constructurs.  One constructor is like this:
name::name(beginning text, data, ending text)
Lets say beginning text and ending texts are  "begin" and "end"  respectively
so frequently I don't want to define with:
name   variablename("begin", x,"end") but just with
name2   variablename(x) where x is the main data.

ok, now there is (at least) two way to do this:
1. make another subclass and initaialize the beginning and ending text to "begin", and "end".

2. yes? suggestions? one is I think with typedef or #define (preprocessor command)
My problem is I don't know how to type def such a thing, It should be someth like:
typedef name   name2("begin", here should x come somehow, "end");
so that you can define with
name2   variablename(x);
On top of this I'd like the definition:
name2  variablename;
to work to and result in :  
name("begin","end");

or is this just nonsens, any suggestion about the second way of doing what I want?
0
Comment
Question by:moonlight
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1166848
You can't do it with typedef.  (Not that I can see at least.  I certainly never tried before)

You can do it with the preprocessor.  but don't.  you'll regret it.  I don't know when and I don't why, but I do know you'll regret it.  Avoid preprocessor like the plague it is.

I suspect there is a better way to get to wher you want to go.  What is the ultimate goal here?  Why are you doing this?
0
 
LVL 3

Author Comment

by:moonlight
ID: 1166849
it's for an assignment.
0
 
LVL 3

Author Comment

by:moonlight
ID: 1166850
I dont know how to do it with preprocessor either. show me how.
What I know you can have things like:
#define name2(x) name("begin", x, "end")
but then how do I declare variables?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
nietod earned 10 total points
ID: 1166851
You could do
#define name2(Prm)  ("begin",Prm,"end")

SomeType VariableName name2(5);

OR

#define name2(Var,Prm)  Var("begin",Prm,"end")

SomeType  name2(VariableName,5);

0
 
LVL 5

Expert Comment

by:yonat
ID: 1166852
You can use defualt arguments (but then you'll have to change the arguments' order). It looks like that:
    name(void* data, string begining = "begin", string ending = "end");
0
 
LVL 22

Expert Comment

by:nietod
ID: 1166853
Yonat, that sounds much better to me.  But I think there is something special about these parameters, like they are being used as semaphores of some kind.  So I think one has to be at the begining and one at the end.  Just a guess.  
0
 
LVL 3

Author Comment

by:moonlight
ID: 1166854
Thank you nietod, works fine.
And, I'm afraid I can't change the order, besides,
I need to use several of these start and end tags, which means
one default argument can't help..but I hadn't written that of course
ok, thank you both
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question