0

I'm trying to create a cross-platform program. I just created a class and made a function which gets the path of the current user. I wanted to use that path later. But somehow I get these errors :

"/usr/include/x86_64-linux-gnu/sys/stat.h:-1: In member function 'void FileManager::p_getfilepath()':"

"/usr/include/x86_64-linux-gnu/sys/stat.h:105: error: expected unqualified-id before string constant"

"/home/david/VocabularyTrainer/filemanager.cpp:31: error: expected '}' at end of input"

btw the 31th line is the last line here in this code :

void FileManager::p_getfilepath() { #ifdef Q_OS_WIN32 #include <windows.h> #endif #ifdef Q_OS_LINUX #include <sys/stat.h> struct passwd *p; uid_t uid; if ((p = getpwuid(uid = geteuid())) == NULL) { QMessageBox* mb; mb->setText(""); mb->exec(); delete mb; } else { filepath = p->pw_dir; } #endif } 

Anyone knows what's wrong? I'm on linux mint.

4
  • 2
    Are you sure you want to be including a header inside a method like that? I'm almost certain that won't turn out well. Commented Apr 24, 2013 at 17:02
  • I can only include that header if it's on a linux or unix system. Commented Apr 24, 2013 at 17:05
  • 2
    That's fine, but why would you want to do it inside the method? Commented Apr 24, 2013 at 17:05
  • Yeah just realized that Commented Apr 24, 2013 at 17:09

1 Answer 1

2

By including your headers inside your class functions, you're making everything in the header a part of the function.

#ifdef Q_OS_WIN32 #include <windows.h> #endif #ifdef Q_OS_LINUX #include <sys/stat.h> #endif void FileManager::p_getfilepath() { #ifdef Q_OS_LINUX struct passwd *p; uid_t uid; if ((p = getpwuid(uid = geteuid())) == NULL) { QMessageBox* mb; mb->setText(""); mb->exec(); delete mb; } else { filepath = p->pw_dir; } #endif } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.