Note that there are some explanatory texts on larger screens.

plurals
  1. POError with calling variable from a class
    text
    copied!<pre><code>class Vars{ public: char *appData = getenv("AppData"); string dir = strcat(appData, "\\Adam"); }; </code></pre> <p>This is my class</p> <p>And this is how I'm trying to use it:</p> <pre><code>void write(string data){ ofstream outfile(Vars.dir + "\\data"); //here's the error outfile &lt;&lt; data; outfile.close(); } </code></pre> <p>This is the error:</p> <pre><code>main.cpp|88|error: expected ',' or '...' before '.' token| </code></pre> <p>Is this not the way to call variables from a class? Classname.variable/functionname ?</p> <p>EDIT: So after making instances of my Vars class, I'm getting these errors:</p> <pre><code>main.cpp|19|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]| main.cpp|20|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]| main.cpp||In function 'void write(std::string)':| main.cpp|88|error: no matching function for call to 'std::basic_ofstream&lt;char&gt;::open(std::string&amp;)'| main.cpp|88|note: candidate is:| mingw32\4.7.1\include\c++\fstream|702|note: void std::basic_ofstream&lt;_CharT, _Traits&gt;::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits&lt;char&gt;; std::ios_base::openmode = std::_Ios_Openmode]| mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|702|note: no known conversion for argument 1 from 'std::string {aka std::basic_string&lt;char&gt;}' to 'const char*'| main.cpp||In function 'std::string read(std::string)':| main.cpp|96|error: no matching function for call to 'std::basic_ifstream&lt;char&gt;::open(std::string&amp;)'| main.cpp|96|note: candidate is:| mingw32\4.7.1\include\c++\fstream|531|note: void std::basic_ifstream&lt;_CharT, _Traits&gt;::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits&lt;char&gt;; std::ios_base::openmode = std::_Ios_Openmode]| mingw32\4.7.1\include\c++\fstream|531|note: no known conversion for argument 1 from 'std::string {aka std::basic_string&lt;char&gt;}' to 'const char*'| main.cpp||In function 'int read(int)':| main.cpp|107|error: no matching function for call to 'std::basic_ifstream&lt;char&gt;::open(std::string&amp;)'| main.cpp|107|note: candidate is:| mingw32\4.7.1\include\c++\fstream|531|note: void std::basic_ifstream&lt;_CharT, _Traits&gt;::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits&lt;char&gt;; std::ios_base::openmode = std::_Ios_Openmode]| mingw32\4.7.1\include\c++\fstream|531|note: no known conversion for argument 1 from 'std::string {aka std::basic_string&lt;char&gt;}' to 'const char*'| main.cpp|108|error: expected ';' before 'if'| </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload