Member is private..??

This is a discussion on Member is private..?? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Programmer_P As for passing a string to getListOfSupportedAttrs(), like you suggested twice already, the reason that is ...

  1. #31
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by Programmer_P View Post
    As for passing a string to getListOfSupportedAttrs(), like you suggested twice already, the reason that is impractical is because I would need to manually write the string names to match the string names of the html attribute members...
    Let's forget the rest of your detail-happy post for a moment and focus on this part.
    One question: why? Why do you have to hard-code anything? Why is it different to have a string instead of an enum? What makes the enum so magical in this situation?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #32
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Just use std::map<unsigned int,std::string> and be done with it. Move onto something that is far more important and hasn't already been done. It would be nice if the language natively supported this behavior but it does not. However it can be mimicked using one or more of the stl containers.

  3. #33
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I think my method is a lot more efficient...
    Doesn't really sound like it, to be honest, but you should probably stick to your plan/idea at this point.

    Quote Originally Posted by Programmer_P View Post
    Yes, i could pass a string name exactly the same as the string name of a corresponding element or attribute, but if I did that, I might as well just hard-code the string, and not use the function at all. Not to mention all the memory that would be used...
    You are already hardcoding in the form of the enum. I know you have another program to auto generate those, but you could just as easily do something similar with strings. Eg, one decent idea would be to load these from a text file* into something like:
    Code:
    map<string, <vector<string*> > htmltags;
    So the map would be key/value pairs: the key (string) would be the name of the tag, the value (vector) would be a list of possible attributes (these could be pointers into a similar map of attributes with vectors of possible values). That would eliminate the need for some of these functions, I think.

    WRT to memory, that is the point of references and pointers (also, html tag names are generally quite short -- a enum int is still 4 bytes).

    As it is now, it sounds like you are having to do the enum to string conversion basically everywhere you use the enum anyway.

    *also more user friendly, and, in fact, removes the hardcoded aspect completely (which remember, your enum is still hardcoded in -- the fact that you did not type the code out manually has nothing to do with the concept of "hardcoded") since the entire tag list would be loaded at runtime. This would make the functionality "data independent", more extensible, and easier to maintain and adapt.
    Last edited by MK27; 06-04-2010 at 04:41 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #34
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by MK27 View Post
    Doesn't really sound like it, to be honest, but you should probably stick to your plan/idea at this point.
    Good idea...
    You are already hardcoding in the form of the enum. I know you have another program to auto generate those, but you could just as easily do something similar with strings. Eg, one decent idea would be to load these from a text file* into something like:
    Code:
    map<string, <vector<string*> > htmltags;
    So the map would be key/value pairs: the key (string) would be the name of the tag, the value (vector) would be a list of possible attributes (these could be pointers into a similar map of attributes with vectors of possible values). That would eliminate the need for some of these functions, I think.

    WRT to memory, that is the point of references and pointers (also, html tag names are generally quite short -- a enum int is still 4 bytes).

    As it is now, it sounds like you are having to do the enum to string conversion basically everywhere you use the enum anyway.
    No, I only have to use it once for each enum, and I only have a couple of enums.
    *also more user friendly, and, in fact, removes the hardcoded aspect completely (which remember, your enum is still hardcoded in -- the fact that you did not type the code out manually has nothing to do with the concept of "hardcoded") since the entire tag list would be loaded at runtime. This would make the functionality "data independent", more extensible, and easier to maintain and adapt.
    Maybe so, but I meant "hard-coded" as in having to manually type up every string.
    I might try your method, once I practice with maps a little first.

  5. #35
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    Let's forget the rest of your detail-happy post for a moment and focus on this part.
    One question: why? Why do you have to hard-code anything? Why is it different to have a string instead of an enum? What makes the enum so magical in this situation?
    That's more than one question...
    And if you had not forgotten (and/or neglected to read) "the rest of my detail-happy" post, you would know the answer to those questions.
    Quote Originally Posted by Bubba View Post
    Just use std::map<unsigned int,std::string> and be done with it. Move onto something that is far more important and hasn't already been done. It would be nice if the language natively supported this behavior but it does not. However it can be mimicked using one or more of the stl containers.
    You keep talking about std::maps with an unsigned int key value, and a std::string mapped value, but I still haven't seen an example of this working to get the string name of an enum value. I looked at the map reference, but its not really clear how to do something like that with a map, though I'm trying to write something like that right now to test it.
    Last edited by Programmer_P; 06-05-2010 at 09:28 AM.

  6. #36
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    Quote Originally Posted by Programmer_P
    You keep talking about std::maps with an unsigned int key value, and a std::string mapped value, but I still haven't seen an example of this working to get the string name of an enum value. I looked at the map reference, but its not really clear how to do something like that with a map, though I'm trying to write something like that right now to test it.
    I have posted a modified version of C_ntua's example in your other thread.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 2
    Last Post: 04-22-2008, 12:07 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. private data member with public set member function
    By Mario in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2002, 10:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21