Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-10
3
Medium Priority
?
4,447 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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 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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

719 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