1

I found the following code:

class BOOST_FILESYSTEM_DECL path
{

};

Usually a class is defined this way:

class Baloon 
{

};

How can I have two terms in the class declaration? Does somebody knows what BOOST_FILESYSTEM_DECL is used for (boost library)?

Holt
  • 36,600
  • 7
  • 92
  • 139
superNovice92
  • 208
  • 1
  • 9
  • 2
    `BOOST_FILESYSTEM_DECL` is just a macro for `__declspec(dllimport)` (or nothing, if it's not needed). – Paul R Jul 12 '16 at 09:46

4 Answers4

5

If you take a look at how it is defined, all will be clear:

#ifdef BOOST_HAS_DECLSPEC // defined in config system
// we need to import/export our code only if the user has specifically
// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
// libraries to be dynamically linked, or BOOST_FILESYSTEM_DYN_LINK
// if they want just this one to be dynamically liked:
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
// export if this is our own source, otherwise import:
#ifdef BOOST_FILESYSTEM_SOURCE
# define BOOST_FILESYSTEM_DECL __declspec(dllexport)
#else
# define BOOST_FILESYSTEM_DECL __declspec(dllimport)
#endif  // BOOST_FILESYSTEM_SOURCE
#endif  // DYN_LINK
#endif  // BOOST_HAS_DECLSPEC
//
// if BOOST_FILESYSTEM_DECL isn't defined yet define it now:
#ifndef BOOST_FILESYSTEM_DECL
#define BOOST_FILESYSTEM_DECL
#endif

As you can see, it is a macro. It expands to __declspec(dllexport) or __declspec(dllimport) or empty, depending on other macros. See this answer for more details about declspec specifier. In short, it is platform specific feature that is needed for dynamic linking.

Community
  • 1
  • 1
eerorika
  • 232,697
  • 12
  • 197
  • 326
4

It's actually a macro that evaluates to either __declspec(dllimport) or __declspec(dllexport), and it's basically being used by the Boost libraries to tell the compiler to export (for their own code) or import (for external code).

LordWilmore
  • 2,829
  • 2
  • 25
  • 30
1

It is a macro; see here for the definition.

It controls the exposition of the class from the shared library (dll); basically it will land up being a __declspec() (or similar depending on the platform) for either the dllexport when building boost, or dllimport when used in client code.

Niall
  • 30,036
  • 10
  • 99
  • 142
0

The BOOST_FILESYSTEM_DECL is probably a macro, look for the declaration:

#define BOOST_FILESYSTEM_DECL 

to see what it's mean.

Ohad Eytan
  • 8,114
  • 1
  • 22
  • 31
  • 1
    Downvoter, please explain your downvote. This is as I see it a fine answer. It's correct and it teaches the skill needed to avoid asking similar questions later. – Cheers and hth. - Alf Jul 12 '16 at 09:52
  • Also, the question wasn't "what this macro does?", the main problem was he didn't understand this is a macro. – Ohad Eytan Jul 12 '16 at 09:55
  • 1
    Actually, the end of OP's post is *"Does somebody knows what BOOST_FILESYSTEM_DECL is used for (boost library)?"*, so yes, he asked for the purpose of this particular macro. IMO, saying `BOOST_FILESYSTEM_DECL` being a macro is not an answer to such question, because knowing that it comes down to `class __declspec(dllimport) path` just push the problem one step further. – Holt Jul 12 '16 at 09:59
  • 1
    @Cheersandhth.-Alf I didn't vote down, I think the answer is fine. But is it a macro, or isn't it? If it isn't, then looking for `#define BOOST_FILESYSTEM_DECL ` won't help much. **I** know that it is, but a user who doesn't know that might not appreciate the speculative answer. – eerorika Jul 12 '16 at 10:00