Hi all,

I'm trying to set up a typedef for vector type in a header file I've named Container.h
The struct is called Student_info and is in a file called Student_info.cpp with header file Student_info.h

My code in Container.h is as follows;

#ifndef GUARD_Container_h
#define GUARD_Container_h

#include <vector>

typedef std::vector<struct> container_Student_info;  // Two errors here

#endif

I am getting the following errors on the typedef line (6);
error: template argument 1 is invalid
error: template argument 2 is invalid

What am I doing wrong here?

Many thanks.

Recommended Answers

All 7 Replies

Well if you struct is called Student_info then you would use

typedef std::vector<Student_info> container_Student_info;

The syntax for this is

typedef std::vector<type_of_object_you_want_for_the_vector> name

Giving that a try

#ifndef GUARD_Container_h
#define GUARD_Container_h

#include <vector>
#include "Student_info.h"

typedef std::vector<Student_info> container_Student_info;

#endif

With this, I get the same errors as before but also;

error: 'Student_info' was not declared in this scope

The following is Student_info.h

#ifndef GUARD_Student_info
#define GUARD_Student_info

// Student_info header file
#include <iostream>
#include <string>
#include "Container.h"

struct Student_info
{
    std::string name;
    double midterm, final;
    container<double> homework;
};

bool compare(const Student_info&, const Student_info&);
std::istream& read(std::istream&, Student_info&);
std::istream& read_hw(std::istream&, container<double>&);

#endif

Have I made a mistake in Student_info.h perhaps?

You have a circular dependency problem. "Container.h" includes "Student_info.h" which includes "Container.h" which includes "Student_info.h" ... In terms of your declarations, you shouldn't need that. In other words, you shouldn't need to include "Container.h" in the "Student_info.h" file. Remove that include statement and your problem should be solved.

This:

typedef std::vector<Student_info> container_Student_info;

should be this:

typedef std::vector<struct Student_info> container_Student_info;

Of course, you could do this:

typedef struct Student_Info studentinfo_t;
typedef std::vector<studentinfo_t> Student_info_containter_t;

I like to put the trailing _t on the defined types so I know that these are defined types... :-)

@rubberman: This thread is in the C++ forum. The struct Student_info is not needed in C++ (it's accepted by compilers, for compatibility with ancient C dialects, but not commonly used). I think you got a bit confused here.

Thanks guys,
I think I'm on the righht track with it now.

@mike_2000_17 my c++ instructor that I had last semester wanted use to put struct in front every time we used one. I think the guy never even looked at the c++98 standard.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.