Click to See Complete Forum and Search --> : enums


Don Head
March 30th, 1999, 10:34 AM
I am attempting to pass a paramter using a enum variable.


Code Sample:

public:

enum something{THING1, THING2, THING3}


Passing

the_status = the_object.method(parameter1, parameter2, THING1, parameter3)


I have tried the CLASS::enum member way of reference, to no success.


The problem is trying to pass a variable(the enum member) without hardcoding the

enum member name.


If any one has a hint.


Thanks


Don Head

Bore
March 30th, 1999, 10:38 AM
I'd be interested to see your actual code, as I don't see anything wrong with what you're doing. I do this all the time. But I'm confused by your statement, "...without hardcoding the enum member name." Do you really mean, "...without hardcoding a literal number?" If you don't want to type the enum member *name*, then I'm confused.

Don Head
March 30th, 1999, 11:09 AM
the enum statement is :


enum ContractType {TempAssign, Contract, Request}


The call looks like:


the_status = the_loader.DumpContract(jobid, code, UpLoader::TempAssign, etc ...)


the ContractType is calculated out, and this enum value is passed to the DumpContract

method. It will not be possible to hardcode the 'UpLoader::TempAssign' parameter.

This,I assume it would have to be a variable of some type.


I hope this clears up the question


Thanks

Don

Bore
March 30th, 1999, 11:42 AM
Sorry, I didn't mean this when I said, "actual code." I meant something that would supply a context. But better yet, how about saying what's wrong? I mean, you say that you do this "to no success." What's failing? Compiler error? Incorrect results?

Wait--do you mean you want to pass a variable to DumpContract() that indicates the contract type? If that's the case, then you'll need a field in your contract object that indicates the contract type. You can then pass that field into DumpContract(). Does this help at all?

Jim McCreary
March 30th, 1999, 11:53 AM
The declaration for DumpContract would be something like:


int DumpContract(int jobid, int code, enum ContractType type, .....


or the enum isn't really necessary but you might need:


int DumpContract(int jobid, int code, UpLoader::type, .....


Is this what you were looking for?

Don Head
March 30th, 1999, 02:33 PM
Here is some more code & the error message when compiled.

The caller will calculate the ContractCategoryType(based on various other fields)

using the enum,

DECLARATIONS in HH file:

public:

enum ContractCategoryType {TempAssignment, Contract, Request};

virtual Status DumpContract(int process_job_seq_id,

char trans_code,

int contract_id,

ContractCategoryType the_status,

ServiceStatusType the_status,

string service_type_code,

int cust_gsam_no,

string contract_reference,

string station_number,

char rec_del_type,

date billing_start,

date billing_end,

date renewal,

date termination,

date secondary_term,

int pipeline_log_code,

int pricePoint) const;

THE CALL

the_status = the_uploader.DumpContract(JobSeqId,

Code,

applSn,

contractCategoryType, <-- this causes the error in the compile

serviceStatusType, <-- this also causes errors

// UpLoader::TempAssignment, <-- hard coded works

// UpLoader::InProgress, <-- hard coded works

service,

GsamNo,

queuedString,

applStnNo,

recDelType,

billingStart,

billingEnd,

renewal,

termination,

junkDate,

SegCode,

pPoint);

THE ERROR MESSAGE:

QueuedService.cc: In method `class Status QueuedService::DumpTo(const class UpLoader &)':

QueuedService.cc:184: bad argument 4 for function `class Status UpLoader::DumpContract

(int, char, int, enum UpLoader::ContractCategoryType,

enum UpLoader::ServiceStatusType,

class basic_string<char,string_char_traits<char> >,

int, class basic_string<char,string_char_traits<char> >,

class basic_string<char,string_char_traits<char> >,

char, class date, class date, class date, class date,

class date, int, int) const' (type was class UpLoader)

make: The error code from the last command is 1.

(continuing)

Target "All" did not make because of errors.

Compilation exited abnormally with code 2 at Tue Mar 30 11:44:26



I thank you for your time.

Bore
March 30th, 1999, 04:55 PM
Ok, just one last vital piece of info is missing here: how did you declare the two variables contractCategoryType and serviceStatusType?

Dave Lorde
March 31st, 1999, 04:58 AM
> ContractCategoryType the_status,

> ServiceStatusType the_status,


Did you mean to have two arguments with the same name?


It would help to know how the contractCategoryType and serviceStatusType arguments are declared.


Dave

Don Head
March 31st, 1999, 04:02 PM
I would like to thanks those that took the time to reply. I have figured it out.