Memberwise copy

Pages: 12
Hello.What's wrong with the following code snippet?
1
2
3
  for( list<Conference>::iterator it = conferences.begin();it != conferences.end();++it )
           if( strcmp(it->getTitle(),t) == 0 )
	          cf = *it;


thank you in advance
What are you looking for?
A specific Conference in the list of conferences whoe title matches a certain value.then copying it in an object of type Conference(cf).

This is the function in which the error occures:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void User::modifyConference(){
	
  Arbiter   objArbiter;
   Article   objArticle;

   char t[100];
   
   Conference cf;
 
   if( strcmp(session->getUserType(), "manager") )
   {
   	   cout << "enter Conference\'s title you want to modify:[80 characters]" <<endl;
	   cin.getline( t, 80 );
        
 	   for( list<Conference>::iterator it = conferences.begin();it != conferences.end();++it )
           if( strcmp(it->getTitle(),t) == 0 )
	          cf = *it;	//This line errs!!!!!
            
           cf.update();
   }//end if
   
}
Last edited on
No, I mean, what's not working for you? It's hard if not impossible to tell what could be going wrong here without some more information.
1
2
3
4
for( list<Conference>::iterator it = conferences.begin();it != conferences.end();++it )
           if( strcmp(it->getTitle(),t) == 0 )
	          cf = *it;	//This line errs!!!!!
            
Okay, what's the error?
The error is:

91 Z:\media\g_\fff\implementation.cpp instantiated from here


very descriptive an error indeed!

I am using dev-cpp
Last edited on
Post all the error messages.
closed account (EzwRko23)
Welcome to the Template Paradise of Informative Error Messages! :D
Sorry, guys, I couldn't resist.

Change your IDE. Dev-Cpp is ancient and broken, and does not print all the messages.
Use Eclipse CDT or IntelliJ IDEA with a proper plugin. Works great for me.
You can also use Code::Blocks but it is not as feature rich.
Last edited on
Post all the error messages.


ok.
91 Z:\media\g_\fff\implementation.cpp instantiated from here

129 Z:\media\g_\Dev-Cpp\include\c++\3.4.2\bits\list.tcc ISO C++ forbids assignment of arrays
 
436 Z:\media\g_\Dev-Cpp\include\c++\3.4.2\bits\stl_list.h   instantiated from `std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with _Tp = char[101], _Alloc = std::allocator<char[101]>]'  

 
1161 Z:\media\g_\Dev-Cpp\include\c++\3.4.2\bits\stl_list.h   instantiated from `void std::list<_Tp, _Alloc>::_M_insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp = char[101], _Alloc = std::allocator<char[101]>]'  

 
783 Z:\media\g_\Dev-Cpp\include\c++\3.4.2\bits\stl_list.h   instantiated from `void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = char[101], _Alloc = std::allocator<char[101]>]'  


764 Z:\media\g_\fff\implementation.cpp instantiated from here

81 Z:\media\g_\Dev-Cpp\include\c++\3.4.2\bits\stl_construct.h ISO C++ forbids initialization in array new
The error is saying that you can't copy arrays this way:
1
2
char a[10],b[10];
b=a;
I assume Conference::operator=() does something like that in its body to copy the title member. I recommend using an std::string instead.
Alternatively, you could use strncpy().
strncpy, where?
In the operator=() overload, but I strongly recommend using an std::string.
I should first study how to overload a function again!!

thhen, I will have difficulty Serializing a String.
Maybe I assumed something wrong about your code. Why don't you post the complete implementation of Conference?
Last edited on
this is Conference's defiinintion:
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
class  Conference   //implemented
{
   public: 
	Conference(User *);
  	void 		setTitle( char* t ){strcpy(title, t);} 		      		//implemented
	char* 		getTitle(){return title;}                	      		//implemented
  	void 		callForPapers();              		      				//implemented
  	char* 		getConferenceHall(){return hall;}	      				//implemented
 	void 		setConferenceHall( char* avenue){strcpy(hall, avenue);} //implemented
  	void 		createWebsiite(){website = new Website( this);}  		//implemented
  	void  	    addTheme();			                          		    //implemented         
	void 	    showInfo();		 	      					  		    //implemented
    void 	    update();				      				  		    //implemented
    void    	setFee();				                      		    //implemented
    int 	    getFee(){return fee;}                         		    //implemented
	void        setManagerID(char id[11]){strcpy(managerID,id);}        //implemented
	char*       getManagerID(){return managerID;}
	void 		showThemes();
  	Time 	     submissionDeadline;
  	list<char[101]> themes;
  	char         anouncement[100];
  	Website*     website;
	User		 manager;	
        
   private:
   	       char      title[100];
   	       char      hall[100];
		   char		 managerID[11];
           int 		 fee;


and here, the implementation:

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
Conference::Conference(User *oManager)

{

   cout << "******************conference c-tor******************************" << endl;

	manager = *oManager;

}

/************************************************************/

void Conference::setFee()

{

  int f;



  cout << "enter the fee" << endl;

  cin >> f;



fee = f>0?f:0;

}

/***************************************************************/

void Conference::update()

{

  char h[100]="";



  cout << "\thall is:\t"<< hall << "\nenter new hall(Enter for no change)" << endl;

  cin >> h;



  if( !strcmp(h, "") )

    strcpy(hall, h );



     strcpy(h, "");  



   cout << "\tTitle is:\t"<< title << "\nenter new Title(Enter for no change)" << endl;

   cin >> h;



     strcpy(h, "");  



  if( !strcmp(h, "") )

    strcpy(title,  h );  



   strcpy(h,"");



   cout << "\tanouncement is:\t"<< anouncement << "\nenter new Title(Enter for no change)" << endl;

  cin >> h;



  if( !strcmp(h, "") )

  {

     strcpy(anouncement, h );

     callForPapers();

  }



  cout << "\tparticipation fee is:\t"<< fee << "\nenter new paticipation fee(Enter for no change)" << endl;

  cin >> fee;



}//end Conference::update()

/*******************************************************/

void   Conference::showInfo()

{

  cout << "\thall:\t"<< hall << "\n\ttitle:\t" << title << endl;

  cout << "themes:" << endl;

  cout << "       ";



  for( list<char[101]>::iterator it = themes.begin();it != themes.end();++it )



     cout << "\t" << *it;

   

}

/****************************************************/

void Conference::callForPapers()

{

   cout << anouncement;

} 

/*************************************************/

void Conference::addTheme()

{

   char theme[101];



   cout << "Enter the theme" << endl;

   cin.getline( theme, 100 );

   

   themes.push_back( theme );

}

/***********************************************/

void Conference::showThemes()

{

	list<char[101]>::iterator it = themes.begin();

	for( ;it!= themes.end();++it )

	{

		cout << *it << endl;

	}

	  

}

hello?!
I got nothing.
ok I changed the
list<char[101]> themes

to
 
char themes [100][100]


and I changed the related code accoedingly

the error disappeared
but now I get linker error.could u plz help me with the link error?
Last edited on
hello?!
Pages: 12