Rimoun
Rimoun

Reputation: 495

'class' type redefinition error with header guards C++

To my understanding, header guards are used to avoid accidentally including something multiple times. However, when I include a class multiple times I still get a redefinition error. Shouldn't the header guards take care of this? //animal.h

#ifndef ANIMAL_H
#define AMIMAL_H

class Animal {};

#endif

//main.cpp

#include"animal.h"
#include"animal.h"

Error C2011: 'Animal' : 'class' type redefinition

Upvotes: 1

Views: 1053

Answers (1)

Bill Lynch
Bill Lynch

Reputation: 81936

#ifndef ANIMAL_H
#define AMIMAL_H
         ^

Those aren't both ANIMAL_H.

Upvotes: 6

Related Questions