CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: enums

  1. #1
    Join Date
    Mar 1999
    Posts
    4

    enums



    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

  2. #2
    Join Date
    Apr 1999
    Posts
    191

    Don't understand



    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.

  3. #3
    Join Date
    Mar 1999
    Posts
    4

    Re: Don't understand



    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

  4. #4
    Join Date
    Apr 1999
    Posts
    191

    Keep trying



    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?

  5. #5
    Join Date
    May 1999
    Location
    Houston, Texas
    Posts
    81

    Re: Don't understand





    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?



    Who was that masked man?

  6. #6
    Join Date
    Mar 1999
    Posts
    4

    Re: Keep trying



    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:umpTo(const class UpLoader &amp':

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

    (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.

  7. #7
    Join Date
    Apr 1999
    Posts
    191

    How did you declare variables?



    Ok, just one last vital piece of info is missing here: how did you declare the two variables contractCategoryType and serviceStatusType?

  8. #8
    Join Date
    Apr 1999
    Posts
    383

    Re: Keep trying



    > 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



  9. #9
    Join Date
    Mar 1999
    Posts
    4

    Re: Don't understand



    I would like to thanks those that took the time to reply. I have figured it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured