C++ .cpp file do not see variables from .h -


i have written program in c++. first have wrote (normally not write in c++) , wanted put variables in header , code in .cpp file. problem class in .cpp not see variales - "identifier undefined".

a.h

#include <iostream> #include <string> #include <cmath> #include <vector>  using namespace std;  class hex {  private:     int n;     string value;     bool negative = false;  public:      hex();      bool iscorrect();      string getvalue();      void setvalue(); }; 

a.cpp

#include "a.h" #include "stdafx.h"       class hex {      public:       hex(int n, string w) { //some implementation }  //rest class } 

what i'm doing wrong? if important i'm working on vs 2013.

you're defining class twice, once in header file , once in .cpp file. assuming want declare functions in header file , define them in .cpp file way go : header:

#include <iostream> #include <string> #include <cmath> #include <vector>  using namespace std;  class hex {  private:     int n;     string value;     bool negative;  public:      hex(int n, string w);      bool iscorrect();      string getvalue();      void setvalue(); }; 

.cpp file:

#include "a.h" #include "stdafx.h"      hex::hex(int n, string w) : negative(false) { /*some implementation*/ } //rest class , definitions of bool iscorrect(); string getvalue(); void setvalue(); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -