Class type redefinition error

I am currently working on a lab and I have been trouble shooting a class type redefinition error with no luck.

1
2
3
4
5
6
7
8
9
1>c:\users\...\desktop\lab11\lab11\vans.h(13): error C2011: 'Vans' : 'class' type redefinition
1>c:\users\...\desktop\lab11\lab11\auto.h(29) : see declaration of 'Vans'
1>c:\users\...\desktop\lab11\lab11\vans.cpp(12): error C2027: use of undefined type 'Vans'
1>c:\users\...\desktop\lab11\lab11\auto.h(29) : see declaration of 'Vans'
1>c:\users\...\desktop\lab11\lab11\vans.cpp(12): error C2062: type 'void' unexpected
1>c:\users\...\desktop\lab11\lab11\vans.cpp(13): error C2143: syntax error : missing ';' before '{'
1>c:\users\...\desktop\lab11\lab11\vans.cpp(13): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\...\desktop\lab11\lab11\vans.cpp(22): error C2027: use of undefined type 'Vans'
...

This is followed by about forty or so more errors all along the same lines of things are not declared. I assume the key is the "Class type redefinition" part.

Currently I have a program with seven files looking something like this

Auto.h
1
2
3
4
5
6
7
8
9
#ifndef AUTO_H
#define AUTO_H

class Auto
{
  public:
...
};
#endif 


Auto.cpp
1
2
3
4
#include "Auto.h"
#include<cstring>
...
//A bunch of functions   


vans.h
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef VANS_H
#define VANS_H

#include<cstring>
#include "Auto.h"

class Vans: public Auto 
{
public:
...
};
#endif 


vans.cpp
1
2
3
4
#include<iostream>
#include "vans.h"
...
//functions  


suvs.h
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef SUVS_H
#define SUVS_H

#include "Auto.h"
#include<cstring>

class Suvs: public Auto 
{
public:
...
};
#endif 


suvs.cpp

1
2
3
4
#include<iostream>
#include "suvs.h"
...
//Functions  


and

TestLab11.cpp
1
2
3
4
5
6
7
8
9
#include<iostream>

#include "suvs.h"
#include "vans.h"

int main()
{
...
}



From what I have been reading the problem comes from having your header file be called more than once and that having the Include guards on the header files would fix it. So what I am asking, are my guards syntax wrong or are my #includes way out of line?

Using Microsoft Visual Studio and I can give the full files if needed.

Thanks for any feed back or help.
1>c:\users\...\desktop\lab11\lab11\auto.h(29) : see declaration of 'Vans'


The compiler seems to think you have a declaration of Vans on line 29 of auto.h. Do you have a forward declaration there, by chance?
Please show all compiling errors with your code here. :)
So thanks to cire I found that in my auto.h file I had made a declaration and forgotten about it.

I removed the other declarations and the program worked fine.
Topic archived. No new replies allowed.