Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 28
White board coding practice 3 77
operator overload: incompatible type and too many params 5 62
Create a path if not exists 7 67
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

947 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now