cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
class redefinition / header guards not w
class redefinition / header guards not working
Jun 8, 2009 at 4:31pm UTC
whosecalling
(8)
I am using Visual C++ 2008 Express Edition
I have the following header class.h:
#ifndef GUARD_CLASS_H
#define GUARD_CLASS_H
#include <vector>
#include <string>
class myclass {
};
<member fns definitions>
#endif // GUARD_CLASS_H
I have two .cpp files that require this class, so I include "class.h" and get re-definition errors. How can I get around this problem?
Jun 8, 2009 at 4:37pm UTC
Bazzy
(6281)
You shouldn't define functions in headers, they are used for declarations
http://www.cplusplus.com/forum/articles/10627/
Jun 8, 2009 at 4:46pm UTC
whosecalling
(8)
so i moved the member fns (and contructor(s)) into a separate source called class.cpp snd used the #include "class.h" at the top. and that did the trick. was this the right thing to do?
Jun 8, 2009 at 4:58pm UTC
Bazzy
(6281)
Yes
Jun 8, 2009 at 5:29pm UTC
whosecalling
(8)
Thank you very much for your help!
Topic archived. No new replies allowed.