?
Solved

subclass versus typedef/#define

Posted on 1998-06-29
7
Medium Priority
?
269 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
Independent Software Vendors: 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 30 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

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!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 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