0
votes

when i build this project in vs2010, error occurs:

  1. syntax error : missing ';' before identifier 'b'
  2. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  3. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  4. error C2065: 'b' : undeclared identifier

    #ifndef _B_H
    #define _B_H
    
    #include <string>
    
    class B
    {
    public:
        B();
        ~B();
        void showfunc();
    
        string b;
    };
    
    #endif
    
    /***************************/
    // B.cpp
    #include <iostream>
    #include <string>
    #include "B.h"
    using namespace std;
    B::B()
    {
    }
    void B::showfunc()
    {
     cout<<b<<endl;
    }
    /**************************************/
    // main.cpp
    #include <iostream>
    // #include "B.h"
    using namespace std;
    void main()
    { 
    }
    

Please help me!

2
string is in the std namespace. You need std::string b;juanchopanza

2 Answers

1
votes

string is in the std namespace. You need

std::string b; 

You should also be be careful with using namespace std, even in implementation files.

Also, note that void main() is not one of the standard signatures for main in C++. You need

int main() { ...
0
votes

add std to string

std::string b;