Typedef in a header?

This is a discussion on Typedef in a header? within the C++ Programming forums, part of the General Programming Boards category; I am trying to do a problem that I can apply to both lists or vectors using an interator, and ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    110

    Typedef in a header?

    I am trying to do a problem that I can apply to both lists or vectors using an interator, and all I would have to do to change the problem is within a typedef declaration. However it does not work..I was wondering why two things I tried does not work. Can someone help explain this to me please?

    This one just tells me no member is defined within the struct. I have no idea what that means though.

    Code:
    #ifndef GUARD_Student_info
    #define GUARD_Student_info
    
    #include <iostream>
    #include <string>
    #include <vector>
    
    typedef std::vector<double> homework;
    
    struct Student_info{
    	std::string name;
    	double midterm, final;
    	homework;
    };
    
    
    bool compare(const Student_info&, const Student_info&);
    std::istream& read(std::istream&, Student_info&);
    std::istream& read_hw(std::istream&, homework&);
    
    #endif
    This one just can't seem to find the type homework when I refer to it.

    Code:
    #ifndef GUARD_Student_info
    #define GUARD_Student_info
    
    #include <iostream>
    #include <string>
    #include <vector>
    
    struct Student_info{
    	std::string name;
    	double midterm, final;
    	typedef std::vector<double> homework;
    };
    
    
    bool compare(const Student_info&, const Student_info&);
    std::istream& read(std::istream&, Student_info&);
    std::istream& read_hw(std::istream&, homework&);
    
    #endif

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Code:
    struct Student_info{
    	std::string name;
    	double midterm, final;
    	homework;
    };
    homework is a type name. You can't just type a name like int; or double; by itself, because what would be the point? You need to give it a variable name like you did with the other members of your struct.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

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. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  3. Header Files
    By Volair in forum C Programming
    Replies: 2
    Last Post: 12-09-2005, 09:51 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  5. Replies: 6
    Last Post: 04-02-2002, 04:46 AM

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