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