Thread: compile. continue coding. get error from code thats unchanged

  1. #1
    Registered User whackaxe's Avatar
    Join Date
    Mar 2004

    compile. continue coding. get error from code thats unchanged

    i've been continuing to code my file system class today and earlier i added the function FindFirstFile() to my constructor to give it a fndfile handler. when i tired to compile it said it couldn't convert string1 to type const char *. so i made string1 a const char* and then it said it couldn't convert it to a string! i fiddled around a bit and eventually all the errors dissapeared ( i even manged to replace the string by a function that returns a string. whoopee!). problem is i can't remember what i did (some crummy little detail probably)

    all's well untill i tried to actually code the fileExist function. coded it, tried to compile and i got the same error from the constructor again! i tried reverting my code back to what it was and i still get the same error. there are two reasons

    1) theres one little tiny piece of code that is breaking the whole thing

    2) theres somthing in my IDE/compiler (dev c++/mingw) that i havent undestood which is making it not compile right

    heres the code

    file: fsystem.class.h
    class C_fsystem
               string SZ_fpath;
               string SZ_fname;
               string SZ_fexten;
               HANDLE H_fileExists;
               WIN32_FIND_DATA findFileData;
               void setPath(const string& TMP_buffer){ SZ_fpath = TMP_buffer;}
               void setName(const string& TMP_buffer){ SZ_fname = TMP_buffer;}
               void setExten(const string& TMP_buffer){ SZ_fexten = TMP_buffer;}
               string fullName(void);
               C_fsystem(const string& PARAM_path, const string& PARAM_name, const string& PARAM_exten);
               int fileExists(void);
    //this will output the full path
    string C_fsystem::fullName(void)
    string TMP_path = SZ_fpath;
    TMP_path += SZ_fname;
    TMP_path += ".";
    TMP_path += SZ_fexten;
    C_fsystem::C_fsystem(const string& PARAM_path, const string& PARAM_name, const string& PARAM_exten)
    SZ_fpath = PARAM_path;
    SZ_fname = PARAM_name;
    SZ_fexten = PARAM_exten;
    string TMP_fullName = SZ_fpath+SZ_fname+"."+SZ_fexten;
    H_fileExists = FindFirstFile(fullName(), findFileData);
    int C_fsystem::fileExists(void)
    file: main.cpp
    #define _WIN32_WINNT 0x0400
    //standard includes
    #include <iostream>
    #include <string>
    using namespace std;
    #include <fstream.h>
    #include <windows.h>
    #include <shellapi.h>
    #include <fsystem.class.h>
    int main()
      C_fsystem myfile("D:\\my documents 2\\robin\\cpp sources\\terraserve\\", "main", "cpp");
      cout<<myfile.fullName()<<": checking for this file...."<<endl;
    compiler results:
    In file included from d:\my documents 2\robin\cpp sources\terraserve\main.cpp:17:
    D:\MYDOCU~1\ROBIN\CPPSOU~1\TERRAS~2\fsystem.class. h: In method `C_fsystem::C_fsystem(const string &, const string &, const string &)':
    D:\MYDOCU~1\ROBIN\CPPSOU~1\TERRAS~2\fsystem.class. h:34: cannot convert `string()' from type `string' to type `const CHAR *'

    much respect to you if you take the time to look though this, i know what its like

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    H_fileExists = FindFirstFile(fullName().c_str(), &findFileData);
    and maybe
    int C_fsystem::fileExists(void)
      return(H_fileExists != INVALID_HANDLE_VALUE);
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    And it's also considered bad practise to put any sourcecode in header files. You should just have declarations there.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User whackaxe's Avatar
    Join Date
    Mar 2004
    it did it again

    i tried coding in my fileExists function, and it compiled fine. then when i made a call to it from main, and compiled again, it stopped working. now ive put .c_str() at the end of and it's working again. oh well, at least it works (even though it worked better before...)

    edit for Xsquared: sorry, didn't see your post. so i have to declare what in the header file? just the class and variables+prototypes in the header and then all functions in a .cpp file?
    Last edited by whackaxe; 03-27-2004 at 12:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 01:45 PM
  2. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 09:36 AM
  3. Can you create, edit and compile C code with a C++ IDE?
    By nerdpirate in forum C Programming
    Replies: 4
    Last Post: 05-31-2008, 01:54 AM
  4. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM