Hello,
I wan't to get a private string from class CWDirectory in member function set_path(const char* s) and put it in a member function set_path() in class Directory.
Code:
//cwdirectory.cpp
//class to output the path of the current working directory
#include <iostream>
#include <stdexcept>
#include "cwdirectory.h"
#include "unistd.h"
#define MAXPATHLEN 200
using namespace std;
CWDirectory::CWDirectory()
{
char buf[MAXPATHLEN];
if(getcwd(buf, MAXPATHLEN))
set_path(buf);
else
throw domain_error("pathway not found");
}
string CWDirectory::set_path(const char* s)
{
return path = s;
}
void CWDirectory::get_cwdir()
{
cout << path << endl;
}
.............................................................
//directory.cpp
//class Directory to output the contents of the current
//working directory
#include <iostream>
#include <stdexcept>
#include "cwdirectory.h"
#include "directory.h"
Directory::Directory()
{
set_path();
}
void Directory::set_path()//function not complete
{
CWDirectory cwdir;
cwdpath = cwdir.set_path(buf);//buf causes compiler error
cout << cwdpath << endl;
}
Here is the error I am getting:
[hopchewer@hopchewer linux_com]$ make
g++ -O2 -Wall -Werror -ansi -c -o cwdirectory.o cwdirectory.cpp
g++ -O2 -Wall -Werror -ansi -c -o directory.o directory.cpp
directory.cpp: In member function ‘void Directory::set_path()’:
directory.cpp:17: error: ‘buf’ was not declared in this scope
make: *** [directory.o] Error 1
I am not sure how to get the path from class CWDirectory into class Directory to list the contents of the current working directory.