typedef question

This is a discussion on typedef question within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I know I should be using templates, but our teacher doesn't want us to modify the code she ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    typedef question

    Hey everyone,

    I know I should be using templates, but our teacher doesn't want us to modify the code she gave us except for one part.

    Code:
    class bag
    {
    public:
        typedef ___ value_type;
        the rest of the class...
    Now, I'm trying to make value_type a typedef for a Die class (of my own creation) object. The only issue is, all of the code I have works perfectly fine until I create the following line:

    Code:
    class bag
    {
    public:
        typedef Die value_type;
        the rest of the class...
    Basically I'm wondering if there are special requirements in order for a type def to work with a class object. My professor mentioned that the class you're using has to have a default constructor, assignment op, overloaded == and != .However, I added those to my class and it didn't change the number of errors at all. I've searched online and only noticed that most articles just speak of using fundamental data types so I figured I'd ask.

    Any additional info needed? Feel free to destroy me for leaving it out :-P

    Chap

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    You don't seem to be using typedef's correctly.

    AFAIK, the format should be:
    Code:
    typedef TYPE NAME;
    Ex:
    Code:
    typedef float Die;
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Quote Originally Posted by psychopath
    You don't seem to be using typedef's correctly.

    AFAIK, the format should be:
    Code:
    typedef TYPE NAME;
    That's exactly what he's doing. He's typedefing a class name (Die) as value_type. That's what I read anyway...

    Can you list the errors your getting?
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    errors

    here are a few:

    error C2784: 'bool std:: operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'main_savitch_3::bag::value_type'

    error C2676: binary '==' : 'main_savitch_3::bag::value_type' does not define this operator or a conversion to a type acceptable to the predefined operator

    error C2784: 'bool std:: operator !=(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'main_savitch_3::bag::value_type'

    NOTE: main_savitch_3 is a namespace the teacher wants us to work with.

    Here are my overloaded ops to work with Die objects:
    Code:
    bool operator==(const Die & leftDie, const Die & rightDie)
    {
    	return ( leftDie.getFace() == rightDie.getFace() );
    }
    
    bool operator!=(const Die & leftDie, const Die & rightDie)
    {
    	return ( leftDie.getFace() != rightDie.getFace() );
    }
    At one point I made them member functions and they still didn't work, I'm completely lost right now. Thanks for whatever assistance you can provide.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Where is the code that actually uses "bag::value_type"? It looks like that code is trying to compare a string to a bag::value_type, rather than comparing a bag::value_type to a bag::value_type which is what the operators you posted do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with ZwQueryDirectoryFile for my Driver.
    By taDo in forum Windows Programming
    Replies: 9
    Last Post: 11-27-2008, 07:54 AM
  2. Error: redefinition of typedef xxxx
    By Rocha in forum C Programming
    Replies: 2
    Last Post: 11-24-2008, 08:19 AM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Help...typedef struct...confusing...
    By darkchild in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 07:03 AM
  5. question about typedef
    By volk in forum C++ Programming
    Replies: 8
    Last Post: 05-30-2003, 10:53 PM

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