Note that there are some explanatory texts on larger screens.

plurals
  1. POIdentifying error that is causing "non-POD type 'class segment' "
    primarykey
    data
    text
    <p><em>Section of my code where error is occuring:</em></p> <pre><code>int disk::access (const char fname[]){ int char_count=77; int actual_count=0; //just to pass the tests. char c; cout &lt;&lt; "the file name is " &lt;&lt; fname &lt;&lt; ", and the mode is " &lt;&lt; mode &lt;&lt; endl; if(strcmp(mode, "w")==0){ for (int i = 0; i &lt; size; i++) { //cout &lt;&lt; "sgm to be written is " &lt;&lt; sgm[i]; fp=fopen(fname, "w"); fprintf(fp, "%s\n",sgm[i]); } fclose(fp); } if(strcmp(mode,"a")==0){ fp=fopen(fname, "a"); fprintf(fp, "%s\n", sgm); fclose(fp); } fp=fopen(fname, "r"); do{ c=fgetc(fp); if(c!=' ' &amp;&amp; c!='\n') actual_count++; }while(c!=EOF); fclose(fp); return actual_count; } </code></pre> <p><em>my error:</em></p> <blockquote> <p>disk.cpp: In member function 'int disk::access(const char*)':</p> <p>disk.cpp:67: warning: cannot pass objects of non-POD type 'class segment' through '...'; call will abort at runtime</p> </blockquote> <p><em><strong>EDIT</em></strong> line 67 is: fprintf(fp, "%s\n",sgm[i]);</p> <p><em><strong>EDIT</em></strong> SGM:</p> <p>the cpp code:</p> <pre><code>disk::disk(int num_of_segments, const char* temp_mode){ size=num_of_segments; sgm = new segment[size]; //initializes num_of_segments in a disk count=0; if(strcmp(mode, "w")!=0||strcmp(mode, "a")!=0){ strcpy(mode, "w"); } } disk::disk(){ sgm = new segment[20]; //initialize 20 segments in a disk size=20; //keeps track of how many are initialized count=0; //keeps track of how many are added strcpy(mode, "w"); //initialize disk access mode to w } </code></pre> <p>the header code:</p> <pre><code>class disk { private: int size, count; //to keep a track of number of segments char mode [2]; //a for append and w for write segment* sgm; FILE *fp; public: disk(int num_of_segments, const char *temp_mode); disk(); ~disk(); const char* get_mode( ) const; segment get_segment(int pos) const; int get_segment_count( ) const; const segment* get_all_segments( ) const; int access(const char fname[ ]); disk&amp; operator+=(const segment &amp;rhs); disk&amp; operator=(const disk &amp;dk); }; </code></pre> <p>I haven't come across a warning like this before. I did some searching and from what I gathered POD is "plain old data that is a struct without constructors, destructors and virtual members functions." -Greg Hewgill</p> <p>So if I understood that correctly, my error is that I do have constructors or destructors and or virtual member functions because it is non-POD?</p> <p>I think I'm just confusing myself, I'm not sure how to go about fixing this error or even pinpointing where the problem is occuring.</p> <p>All suggestions are welcome and greatly appreciated,</p> <p>thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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