I'm a begginer and I don't know how to deal with this task :     *This class is intended to be instantiated with a src character string as a parameter of its constructor. It must then:    *-&gt; Determine the type of file to which src corresponds (among: image, video, security plan [.mps]), using the extension    *-&gt; Check if the file corresponding to src exists.    *-&gt; If the file does not exist, the src member variable of File is initialized with a path to a file by default, depending on the type    *(if the desired file was an image, src will contain the path to an &quot;Error&quot; image, ditto for videos and mps).   In File.h :         class File{         private:             string src;             string type;                  public:             string description;                      File();             File(string src);            ~File();             bool exists();     };  In File.cpp: File::File(string src):src(src){}  bool File::exists(){}  The thing is that I don't know how to check the file's exention from a string :/ .
64483
Given a string "filename.conf", how to I verify the extension part?  I need a cross platform solution.
22560
I'm writing code to do Xml serialization. With below function.  public static string SerializeToXml(object obj) {     XmlSerializer serializer = new XmlSerializer(obj.GetType());     using (StringWriter writer = new StringWriter())     {         serializer.Serialize(writer, obj);         return writer.ToString();     } }   If the argument is a instance of class without parameterless constructor, it will throw a exception.     Unhandled Exception:   System.InvalidOperationException:   CSharpConsole.Foo cannot be serialized   because it does not have a   parameterless constructor.    at   System.Xml.Serialization.TypeDesc.CheckSupported()   at   System.Xml.Serialization.TypeScope.GetTypeDesc(Type   type, MemberInfo sourc e, Boolean   directReference, Boolean throwOnError)   at   System.Xml.Serialization.ModelScope.GetTypeModel(Type   type, Boolean direct Reference)    at   System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type   type , XmlRootAttribute root, String   defaultNamespace)    at   System.Xml.Serialization.XmlSerializer..ctor(Type   type, String defaultName space)    at   System.Xml.Serialization.XmlSerializer..ctor(Type   type)   Why must there be a parameterless constructor in order to allow xml serialization to succeed?  EDIT: thanks for cfeduke's answer. The parameterless constructor can be private or internal.
111415
I have a Generic class like that :  public class Repository&lt;T&gt; {...}   And I need to instance that with a string ... Example :  string _sample = "TypeRepository"; var _rep = new Repository&lt;sample&gt;();   How can I do that? Is that even possible?  Thanks!
82685
I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.  Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?    Are there special directories?
57492
I have a helper class pulling a string from an XML file. That string is a file path (so it has backslashes in it). I need to use that string as it is... How can I use it like I would with the literal command?  Instead of this:  string filePath = @"C:\somepath\file.txt";   I want to do this:  string filePath = @helper.getFilePath(); //getFilePath returns a string   This isn't how I am actually using it; it is just to make what I mean a little clearer. Is there some sort of .ToLiteral() or something?
21989
Very simply put:  I have a class that consists mostly of static public members, so I can group similar functions together that still have to be called from other classes/functions.  Anyway, I have defined two static unsigned char variables in my class public scope, when I try to modify these values in the same class' constructor, I am getting an "unresolved external symbol" error at compilation.  class test  { public:     static unsigned char X;     static unsigned char Y;      ...      test(); };  test::test()  {     X = 1;     Y = 2; }   I'm new to C++ so go easy on me. Why can't I do this?
104493
I have Library on which I have created a ribbon button. On click of the button I am trying to identify if the selected item is a folder or a file. below if the code snippet that I am using:  var context = SP.ClientContext.get_current(); var web = context.get_web();  var items = SP.ListOperation.Selection.getSelectedItems(context);  var currentLibrary = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList(context));  var index; for (index in items) {     var selectedItem = currentLibrary.getItemById(items[index].id);     // Need to identify if 'selectedItem' is folder or not     console.log("FileSystemObjectType = " + selectedItem.FileSystemObjectType); // Returns 'undefined'     console.log("get_file = " + selectedItem.get_file()); // Returns 'SP.ListItem' object     console.log("get_folder = " + selectedItem.get_folder()); // Returns 'SP.ListItem' object }   Taking reference from  I tried to use FileSystemObjectType but in my case it ends up showing undefined for both file and folder. Also if I try to check if the selected item is a file or folder using below code it always return true.  if(item.FileSystemObjectType == SP.FileSystemObjectType.Folder) {     // Always returns true }   What am I doing wrong here? How can I identify if the selected item in Library is a file or a folder?
69649
I'm using GCC; __FILE__ returns the current source file's entire path and name: /path/to/file.cpp. Is there a way to get just the file's name file.cpp (without its path) at compile time? Is it possible to do this in a portable way? Can template meta programming be applied to strings?  I am using this in an error logging macro. I really do not want my source's full path making its way into the executable.
30038
Linux determines the type of a file via a code in the file-header. It doesn't depend on file-extensions for to know which software is to use for opening the file.  That's what I remember from my education. Please correct me in case I'm wrong!  Working a bit with Ubuntu systems recently: I see a lot of files on the systems which have extensions like .sh, .txt, .o, .c  Now I'm wondering: Are these extensions are meant only for humans? So that one should get an idea what kind of file it is?  Or does they have some purpose for the operating-system too?
25435
Is there a way to create an instance of a class based on the fact I know the name of the class at runtime. Basically I would have the name of the class in a string.
91805
Short prestory. Typical problem: you have a lot of small string and you want to concatenate them all in one big string. The code like for(Integer i = 0; i &lt; smallStringsSize; i++){     bigString += smallStrings[i]; }  will solve this problem, but it has to produce a lot of unnecessary string objects that consume your heap. That is why Java has classes like StringBuilder and StringBuffer that allow you to solve this problem wihtout consuming too many memory. Thus, I decided to try to do my own StringBuilder in apex. String class has two methods that looked suitable for it:   and  . Here is the code that i used to test these methods against &quot;+=&quot; concatenantion (ready to execute in anonymous): List&lt;String&gt; chars = new List&lt;String&gt;(); List&lt;Integer&gt; charsCode = new List&lt;Integer&gt;(); Integer size = 10000; String chartToAdd = 'Ω'; for(Integer i = 0; i &lt; size; i++){     chars.add(chartToAdd);     charsCode.add(String.valueOf(chartToAdd).charAt(0)); } String joinS = '', forS = '', fromS = ''; Integer initialHeapSize = Limits.getHeapSize(); Integer initialCPUtime = Limits.getCpuTime(); System.debug('initialHeapSize ' + initialHeapSize); System.debug('initialCPUtime ' + initialCPUtime); joinS = String.join(chars, ''); Integer joinHeapSize = Limits.getHeapSize() - initialHeapSize; Integer joinCPUtime = Limits.getCpuTime() - initialCPUtime; System.debug('-------- String.join ---------'); System.debug('joinHeapSize ' + joinHeapSize); System.debug('joinCPUtime ' + joinCPUtime); for(Integer i = 0; i &lt; size; i++){     forS += chars[i]; } Integer forHeapSize = Limits.getHeapSize() - joinHeapSize - initialHeapSize; Integer forCPUtime = Limits.getCpuTime() - joinCPUtime - initialCPUtime; System.debug('-------- for each += ---------'); System.debug('forHeapSize ' + forHeapSize); System.debug('forCPUtime ' + forCPUtime); fromS = String.fromCharArray(charsCode); Integer fromHeapSize = Limits.getHeapSize() - forHeapSize - joinHeapSize - initialHeapSize; Integer fromCPUtime = Limits.getCpuTime() - forCPUtime - joinCPUtime - initialCPUtime; System.debug('-------- String.fromCharArray ---------'); System.debug('fromHeapSize ' + fromHeapSize); System.debug('fromCPUtime ' + fromCPUtime); System.debug(''); System.debug('-------- strings ----------'); System.debug('joins ' + joins); System.debug('fors ' + fors); System.debug('fromS ' + fromS);  The result of this code execution:  initialHeapSize 161166 initialCPUtime 242 -------- String.join --------- joinHeapSize 10016 joinCPUtime 17 -------- for each += --------- forHeapSize 10024 forCPUtime 48 -------- String.fromCharArray --------- fromHeapSize 10016 fromCPUtime 5  As you can see, the heap size for each approach is so close to 10 kilobytes, what is a size of the string of 10 000 characters (size) if each character takes only one byte. In case of creating 10 000 additional string objects, the heap size would be a bit more than 50 megabytes (10 000 * (1 + 10 000)/2). Taking into consideration the above,  Does not the '+=' concatenation create any additional string objects that devour your heap? Did not I miss anything? I am so amazed.  As you see, I use Omega 'Ω' as a chartToAdd. It has  the high-surrogate code point equals to 937, that needs at least 2 bytes to be encoded. How can 10 000 Omegas consume only 10 000 bytes of the heap size?  What weightful reasons Salesforce has that they do not to add the character data type? Any ideas?
72830
Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually?  I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my program and using it (marked as TWO). Am I assigning a variable in the stack to a field in ONE? Can the code be referencing to a dangling pointer which in this case worked because the program was small enough?  I've compiled and ran it, it worked fine but I'm having a strange crash in my actual program where I'm assigning string literals to fields of the class like this and I suspect the case I mentioned above.  #include &lt;iostream&gt;  using namespace std;  class MemoryLeak { private:     char *s; public:     MemoryLeak() {}      void store()     {         s = "Storing a string"; // ONE     }      char *retrieve()     {         return s;     } };  int main() {     MemoryLeak *obj = new MemoryLeak();     obj-&gt;store();     cout &lt;&lt; obj-&gt;retrieve() &lt;&lt; endl; // TWO     delete obj;     return 0; }   Should I be declaring the variable "s" as a char array instead of a pointer? I'm planning to use std::string, but I'm just curious about this.  Any pointers or help is, as always, much appreciated :) Thanks.
31267
Is there a method in the System.IO namespace that checks the validity of a filename?  For example, C:\foo\bar would validate and :"~-* would not  Or a little trickier, X:\foo\bar would validate is there is an X: drive on the system, but wouldn't otherwise.  I suppose I could write such a method myself, but I'm more interested in a built-in one.
13958
As a  developer I'm used to running through constructors:    class Test {     public Test() {         DoSomething();     }      public Test(int count) : this() {         DoSomethingWithCount(count);     }      public Test(int count, string name) : this(count) {         DoSomethingWithName(name);     } }   Is there a way to do this in C++?  I tried calling the Class name and using the 'this' keyword, but both fail.
76907
I am having some issues with the  type. Whenever I try to edit and save a form that has a managed_file element in it an error occurs: The file  used in the Picture field may not be referenced.  This is the code I'm using:  function foo_form ($form, &amp;$form_state, $foo) {     ...        $form['file'] = array(     '#type' =&gt; 'managed_file',     '#title' =&gt; t('Picture'),     '#default_value' =&gt; (isset($foo-&gt;file-&gt;fid) ? $banner-&gt;foo-&gt;fid : ''),     '#upload_location' =&gt; variable_get('foo_upload_location'),   );    if (isset($foo-&gt;file)) {     $form['current_file'] = array(       '#type' =&gt; 'hidden',       '#value' =&gt; $foo-&gt;file-&gt;fid,     );   }   ...   $form['submit'] = array(     '#type' =&gt; 'submit',     '#value' =&gt; t('Save'),   );   return $form;  }  function foo_form_submit ($form, &amp;$form_state) {   $foo = (object)$form_state['values'];    $current_file_set = isset($form_state['values']['current_file']);    if ($form_state['values']['file'] != 0 &amp;&amp; !$current_file_set) {     // Load the file uploaded in the form.     $file = file_load($form_state['values']['file']);      $file-&gt;status = FILE_STATUS_PERMANENT;      file_save($file);      $foo-&gt;file = $file-&gt;fid;   } else if ($form_state['values']['file'] != 0 &amp;&amp; $current_file_set) {      // If we are uploading a different picture, delete the old one and save the     // new one. If not, don't do anything.     if ($form_state['values']['current_file'] != $form_state['values']['file']) {       file_delete(file_load($form_state['values']['current_file']));       // Load the file uploaded in the form.       $file = file_load($form_state['values']['file']);        $file-&gt;status = FILE_STATUS_PERMANENT;        file_save($file);        $foo-&gt;file = $file-&gt;fid;     }   } else {     file_delete(file_load($form_state['values']['current_file']));     $foo-&gt;file = null;   }    ... }   I traced the error back to the  function in modules/file/file.module but don't know anything about the file references.
113003
We are using the CString class throughout most of our code. However sometimes we need to convert to a char *. at the moment we have been doing this using variable.GetBuffer(0) and this seems to work ( this mainly happens when passing the Csting into a function where the function requires a char *). The function accepts this and we keep going.  However we have lately become worried about how this works, and whether there is a better way to do it.  The way i understand it to work is it passes a char pointer into the function that points at the first character in the CString and all works well.  I Guess we are just worried about memory leaks or any unforseen circumstances where this might not be a good idea.
24839
class Outer {      class Inner {     public:         Inner() {}         void func() ;     };  private:     static const char* const MYCONST;     int var; };  void Outer::Inner::func() {     var = 1; }  const char* const Outer::MYCONST = "myconst";   This errors out when I compile with class Outer::Inner' has no member named `var'