Namespace dllimport error

I've got 2 functions in a namespace, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// util.h
#include <string>
using namespace std;

#ifdef UTILDLL
#define UTILPART __declspec(dllexport)
#else
#define UTILPART __declspec(dllimport)
#endif

namespace funcs
{
    string UTILPART func1 (int);
    int UTILPART func2 (string);
}


The DLL which contains these functions looks like this:

1
2
3
4
5
6
// util.cpp

#define UTILDLL
#include "util.h"

// define the functions here 


The executable which uses these functions looks like this:

1
2
3
4
// exec.cpp
#include "util.h"

// Do stuff involving those functions 


When I compile this in VS 2010, I don't get any errors for the DLL, but the executable gives me:

util.h(13): error C2146: syntax error : missing ';' before identifier 'string'
util.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
util.h(14): error C2144: syntax error : 'int' should be preceded by ';'
util.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
util.h(14): error C2086: 'int utilityFunctions::UTILPART' : redefinition
          util.h(13) : see declaration of 'utilityFunctions::UTILPART'
util.h(14): error C2086: 'string funcs::UTILPART' : redefinition
          util.h(13) : see declaration of 'funcs::UTILPART'


Does anyone know why it says this?
Last edited on
Don't put using namespace ... in a header file, it has global impact, and won't behave as you think.

There's more to this than you're showing. Where did the name utilityFunctions come from?
There's more to this than you're showing


it's a big file which is otherwise working properly, so i cut everything but the important bits (ie this namespace) and made it more readable. utilityFunctions is the implementation name for funcs
Have you removed using namespace std from your header file(s)?

If you really want to see what's going on, make the preprecessor write its output to a file and look at the file. Visual Studio will generate a .i file for preprocessor output.
Topic archived. No new replies allowed.