Reason of error?

C

contactmayankjain

Hi

Why this code is giving me an error. If I uncomment the commented line
and make my structure global it work fine.

#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
// struct student{
// char name[20];
//int rollno;
//};
int main(int argc, char *argv[])
{
struct student{
char name[20];
int rollno;
};
vector<struct student>stu;

system("PAUSE");
return 0;
}

Regards
Mayank Jain(Nawals)
 
N

Neelesh Bodas

Hi

Why this code is giving me an error. If I uncomment the commented line
and make my structure global it work fine.

#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
// struct student{
// char name[20];
//int rollno;
//};
int main(int argc, char *argv[])
{
struct student{
char name[20];
int rollno;
};
vector<struct student>stu;

system("PAUSE");
return 0;

}

C++ standard 14.3.1 (2) : A local type ... shall not be used as a
template argument or a template type parameter

Since student is a local class, using it as template argument for
std::vector is not allowed

-N
 
V

Victor Bazarov

Why this code is giving me an error. If I uncomment the commented line
and make my structure global it work fine.

#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
// struct student{
// char name[20];
//int rollno;
//};
int main(int argc, char *argv[])
{
struct student{
char name[20];
int rollno;
};
vector<struct student>stu;

system("PAUSE");
return 0;
}

Regards
Mayank Jain(Nawals)

First off, please read the FAQ 5.8. It helps to supply _all_ the
information you can, for example, *what* error you get. Have you
read the error message? What in it do you not understand? See,
without actually knowing what the error message says, we can't help
you by explaining it.

I will venture a guess that your compiler complains because you're
not allowed to use local classes as template arguments. Local
classes don't have linkage and as such are prohibited from use in
template (according to the current standard).

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top