Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

19 Experts available now in Live!

Get 1:1 Help Now