Redefinition of Class Error

Nov 6, 2011 at 11:20pm
This is an error unfortunately I've not had the joy of debugging before, so I'm not sure what's going on with this one. Here is the list of errors I'm receiving:


In file included from /u/zon-d2/ugrad/jlev222/qv-mvc/nameview.h:2,
from /u/zon-d2/ugrad/jlev222/qv-mvc/namefirstview.h:1,
from /u/zon-d2/ugrad/jlev222/qv-mvc/main.cpp:3:
/u/zon-d2/ugrad/jlev222/qv-mvc/namemodel.h:4: error: redefinition of ‘class NameModel’
/u/zon-d2/ugrad/jlev222/qv-mvc/namemodel.h:4: error: previous definition of ‘class NameModel’
In file included from /u/zon-d2/ugrad/jlev222/qv-mvc/nameview.h:2,
from /u/zon-d2/ugrad/jlev222/qv-mvc/namelastview.h:1,
from /u/zon-d2/ugrad/jlev222/qv-mvc/main.cpp:4:
/u/zon-d2/ugrad/jlev222/qv-mvc/namemodel.h:4: error: redefinition of ‘class NameModel’
/u/zon-d2/ugrad/jlev222/qv-mvc/namemodel.h:4: error: previous definition of ‘class NameModel’
In file included from /u/zon-d2/ugrad/jlev222/qv-mvc/namelastview.h:1,
from /u/zon-d2/ugrad/jlev222/qv-mvc/main.cpp:4:
/u/zon-d2/ugrad/jlev222/qv-mvc/nameview.h:4: error: redefinition of ‘class View’
/u/zon-d2/ugrad/jlev222/qv-mvc/nameview.h:4: error: previous definition of ‘class View’
/u/zon-d2/ugrad/jlev222/qv-mvc/main.cpp: In function ‘int main(int, char**)’:
/u/zon-d2/ugrad/jlev222/qv-mvc/main.cpp:10: error: variable ‘QTimer timer’ has initializer but incomplete type
make[2]: *** [CMakeFiles/qt_mvc.dir/main.o] Error 1
make[1]: *** [CMakeFiles/qt_mvc.dir/all] Error 2
make: *** [all] Error 2

I know this is a lot, but I'm only paying attention to the top, I'm hoping this is an include error, but I'm not sure. Also, I can provide the source code and headers if needed, but I warn ahead of time... they aren't huge files, but 11 in total including main.cpp.

Also, it may be important to note I'm using CMake to build this, but CMake doesn't seem to have issues.

Any ideas?
Nov 6, 2011 at 11:32pm
Given the prev definitions are in the same file, it looks like you're including the same headers multiple times. So you need to add guard code

1
2
3
4
5
6
#ifndef Included_NameModel_H
#define Included_NameModel_H

// Existing code goes here

#endif // Included_NameModel_H 


Using whatever naming convention you like.

Or, if you compiler supports it, add #pragma once at the start of the header
Nov 7, 2011 at 12:17am
@andywestken Thanks, I'll give this a shot and let you know how it works out.
Nov 7, 2011 at 12:45am
@andywestken This cleared it up, thanks!
Topic archived. No new replies allowed.