1

I'm getting crazy. I just have a header and cpp and it doesn't compile:

the .h is the following:

#pragma once

#include <string>
#include <map>
#include <windows.h>



class Activate
{
public:
    Activate();
    ~Activate();

    int accion(map<string, string>& mapa);
};

and the cpp this one:

#include "Activate.h"
using namespace std;

Activate::Activate()
{
}


Activate::~Activate()
{
}

int Activate::accion(map<string, string>& mapa){}

and I get the error mentioned above:

1>c:\users\dani.roca\desktop\autocad files\mfc dll\project1\project1\activate.h(19): error C2061: syntax error : identifier 'map'
1>c:\users\dani.roca\desktop\autocad files\mfc dll\project1\project1\activate.cpp(13): error C2511: 'int Activate::accion(std::map<_Kty,_Ty> &)' : overloaded member function not found in 'Activate'


#include "Activate.h"
using namespace std;

Activate::Activate()
{
}


Activate::~Activate()
{
}

int Activate::accion(std::map<string, string>& mapa){}

and this

class Activate
{
public:
    Activate();
    ~Activate();

    int accion(std::map<std::string, std::string>& mapa);
};

then new error appeared:

1>LINK : fatal error LNK1561: entry point must be defined

  • 2
    where is main()? you can't compile without main(). main() is life. – Khalil Khalaf Mar 16 '16 at 12:45
  • @PiotrSkotnicki why should I? I am using namespace std already –  Mar 16 '16 at 12:48
  • 1
    "use namespace std" [should be avoided](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). It's sad how many uneducated instructors are teaching this bad programming practice to their students. – Sam Varshavchik Mar 16 '16 at 12:51

1 Answers1

3

Replace int accion(map<string, string>& mapa); with

int accion(std::map<std::string, std::string>& mapa);
//         ^^^^^    ^^^^^        ^^^^^

When you include your header, using namespace std is yet to take effect.

As an alternative you can add using std::map; and using std::string; in your class.

class Activate
{
public:
    Activate();
    ~Activate();

    using std::map;
    using std::string;
    int accion(map<string, string>& mapa);
};
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • Then you should say `using namespace std;` and then include the header. BTW never say `using namespace std;` in production code. – Mohit Jain Mar 16 '16 at 12:49
  • or in a header file. – NathanOliver Mar 16 '16 at 12:55
  • changed this: class Activate { public: Activate(); ~Activate(); int accion(std::map& mapa); }; #include "Activate.h" using namespace std; Activate::Activate() { } Activate::~Activate() { } int Activate::accion(std::map& mapa){ } and new error: 1>LINK : fatal error LNK1561: entry point must be defined –  Mar 16 '16 at 12:56
  • You need a `main` function. – Mohit Jain Mar 16 '16 at 12:57
  • @MohitJain with main new error: 1> LINK : C:\Users\dani.roca\Desktop\autocad Files\MFC DLL\Project1\x64\Debug\Activacion.exe not found or not built by the last incremental link; performing full link –  Mar 16 '16 at 13:00