C++ Error C2143 syntax error: missing ";" before "using namespace" -
this code:
#include <iostream> #include "constructors.h" using namespace std; int main() { animal animal1; animal1.setname("klinton"); animal animal2 = animal1; animal2.speak(); animal2.setname("freddy"); animal2.speak(); return 0; }
and code for: "constructors.h":
#ifndef _constructors_h_ #define _constructors_h_ #include <string> class animal { private: std::string name; public: animal() { cout << "animal created." << endl; } animal(const animal& other): name(other.name) { cout << "animal created copying." << endl; } void setname(std::string name) { this->name = name; } void speak() const { cout << "my name is: " << name << endl; } } #endif // !_constructors_h_
the error has number c2143 , says there missing: ";" before: "using namespace" on line 4 in main.cpp, how fix this?
class definitions have end semicolon.
so, class animal{...};
Comments
Post a Comment