Solved

linux; c++; calling system "mkdir()" from class which has a "mkdir()" method

Posted on 2008-10-10
3
4,416 Views
Last Modified: 2012-06-27
I've got a class "Dirs" which has a "Mkdir()" method.  Inside this method, I'm trying to call the system library function "mkdir(char *, mode_t)" as included from <sys/stat.h> and <sys/types.h>.  However, when I try to call the system version, the compiler keeps telling me it cannot find a matching function in the class.  Is there some special way I need to call mkdir, or do I need to include a system library or something?

Here is the comp output:
./Headers/./Dirs.h: In static member function 'static bool Dirs::Mkdir(Dirs*)':
./Headers/./Dirs.h:235: error: no matching function for call to 'Dirs::mkdir(const char*, int)'
./Headers/./Dirs.h:125: note: candidates are: bool Dirs::mkdir()


I've included the relevant code below.


static bool Mkdir(Dirs *dir) {
    unsigned int pcount;
    string       full;
 
    if(dir->isNull() || dir->isEmpty()) { return false; }
    if(!dir->exists()) {
      pcount = dir->parts();
      for(unsigned int x = 1; x <= pcount; x++) {
        full = dir->path(x);
        if(!Dirs::Exists(full)) {
#ifdef _MSC_VER
          if(_mkdir(full.c_str()) == -1) { return false; }
#else
          if(mkdir(full.c_str(), 0770) == -1) { return false; }
#endif
        }
      }
    }
    return true;
  }
 
  static bool Mkdir(string path) {
    return Dirs::Mkdir(new Dirs(path));
  }

Open in new window

0
Comment
Question by:BaconU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22689627
>./Headers/./Dirs.h:125: note: candidates are: bool Dirs::mkdir()
you have a member function called mkdir and it is trying to link to that function or an overloaded matching member. Rename this member function to something else and you should be fine.
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 22689643
Try to call that using the scope operator, i.e.

          if(::mkdir(full.c_str(), 0770) == -1) { return false; }

Open in new window

0
 

Author Closing Comment

by:BaconU
ID: 31505143
That did it..  I knew it would be something easy.  I had tried using std::, but I knew it wasn't in the std namespace.  Thanks a bunch!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question