Solved

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

Posted on 2008-10-10
3
4,431 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

617 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