Solved

subclass versus typedef/#define

Posted on 1998-06-29
7
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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