Constructors with Points and returning objects with functions, oh my!

Hi,


I'm currently stuck on a problem involving returning an object using a function.I'm very ashamed I can't get this problem on my own, so I was wondering if any users here could possibly point me in the right direction. Be forewarned this is rather lengthy, so will do my best to explain.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class set{


public:
       set(){};
      
         set(string* q){
             string*  p = q;
             
            
              };
      
 
     
 set set_union(set otherSet ) {
    
  /*  
    int j = cardinality();  
  int i = otherSet.cardinality();   
 
  int k = i + j; 
 int l = k -i;
 int l2 = k -j; 
 */ 
  string s[100];
 

string * u ;
u = s; 
 
    
 return  set(u);   
    // The /* */ is just blocked out code that will be used to combine sets.
     }; 


With this code segment I get an error

In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':

<more errors>

Then a very strange thing happens.

I get a file named ios_base.h with a highlighted line at this part

1
2
3
4
5
6
7
8
9
10
11
 
<more code above>
/ _GLIBCXX_RESOLVE_LIB_DEFECTS
  // 50.  Copy constructor and assignment operator of ios_base
  private:
    ios_base(const ios_base&);

    ios_base&
    operator=(const ios_base&);
<more code below> 
 };


The file that is opened is a rigorous 927 lines of code I can't grasp with my current knowledge of the langue.


In attempting to trouble shoot this issue, I believe this is what be wrong, but can't confirm via Google/c++ book/ data structures book.

(Now, I do get a website for the actual large error message, but the context of the page is for iostreams.)

I believe it is either
1. Compiler is wrong, unlikely.

or

2. I ignored some very important rule of the language as the ios_bas.h appearing.

However, I'm assuming IOS here means input output stream, but the problem isn't with that as the file is being read correctly...

Total time debugging: 10 hours.
Total time coding whole file(not being scene): 13 hours.

No, complaints though have learned a lot!


Any pointers on this problem(no pun attended)?



You sure that's the whole class? I see 3 opening brackets, and only two closing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

#include <fstream>
#include <string>
#include<iostream>

using namespace std;

class set{


public:
       set(){};
      
         set(string* q){
             string*  p = q;
             
            
              };
      
 
     
 set set_union(set otherSet ) {
    
    
    int j = cardinality();  
  int i = otherSet.cardinality();   
 
  int k = i + j; 
 int l = k -i;
 int l2 = k -j; 
  
  string s[100];
 // s = new string [k];  

string * u ;
u = s; 
 
    
 return  set(u);   
    
     };
     
                            
void fill_array(string nameoffile);
int cardinality();
bool isMember(string s);  
int size;

          
                 string* p ;
                 ifstream file_check; 
                 

  
  
      };
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                  
     void set:: fill_array(string nameoffile)
          {
               file_check.open(nameoffile.c_str( ));
if (file_check.fail())
         {
cout << "Input file opening failed.  " << endl;
cout << "**************************" << endl;
cout << "*****ABORTING PROGRAM*****" << endl;
cout << "**************************" << endl;     
 abort();}
int size = 6; 
 p = new string [size] ;
 string next; 
int i = 0; 
 while(file_check >> next)
{
                    
 p[i] = next ;           

  i++;          
    
 if (i == size)
 {
       string *save = new string[size * 2];
for ( int i = 0; i < size; i++ )
      save[i] = p[i];
       size *= 2;
       
       delete[]p;
       p = save;
       }

  
  
}
 file_check.close();
	 }
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~              
               
 int set:: cardinality(){
 int i = 0; 
 while (!p[i].empty())
{
 i++;
}
size = i; 
 return i; 
}
  
  
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
  
// have to find the current size, as they could want to know sizze of the new set. 
  
bool set :: isMember(string s){
    
     int current_size = 0;  
 while (!p[current_size].empty())
{
 current_size++;
}
     
     
   for(int i = 0; i <= current_size; i++)
     {
     if( p[i].compare(s) != 0)
   
     return false;
break;
}  
  
     
     
     return true;
    
     
     
     }
 

   



  
  



Is the whole class. It is not set up in terms of C++ standards(syntax). This is also using the Dev Bloodshed C++ IDE.

the //~~~~~~~~~~~~~~~~~~~~~~ separates the functions. All of them work as is with no errors, I understand there might be a logic problems, but haven't began the whole debugging processes due to my lack of knowledge of returning objects :(
Last edited on
Summary of class is: take in a file store each words in a dynamic array. I'm currently trying to combine two arrays in two objects via an array filled with strings and return them.

But, It won't allow me to even return a pointer in a function ....so am currently working on why they won't work and getting big error explained in the 1st post :(

Something so simple wants to blow up my computer :/
When I see the error that you pointed out in the first post, I see an error that, when I get it, generally means that I used one of the templates defined in a library incorrectly. I'm getting a headache trying to decipher the indents in your code, though, so I have to take a break.
Topic archived. No new replies allowed.