Solved

subclass versus typedef/#define

Posted on 1998-06-29
7
262 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now