[prog] Re: C++

wolf wolf at wolfrising.net
Sun Mar 14 01:10:10 EST 2004


Hello : ) Thank you : ) with making the changes you suggest the error 
messages have
changed to the following:

Compiling...
cd.cpp: In function `int main()':
cd.cpp:29: error: no match for `cd& = cd*&' operator
cd.cpp:4: error: candidates are: cd& cd::operator=(const cd&)
cd.cpp: In member function `void cd::getdata()':
cd.cpp:48: error: invalid use of member (did you forget the `&' ?)
cd.cpp:50: error: invalid use of member (did you forget the `&' ?)
cd.cpp:54: error: invalid use of member (did you forget the `&' ?)

I think & stands for a reference to a pointer perhaps?
here's the current update of the program:

#include <iostream>
  using namespace std;

class cd {
  private:
	     char artist[30];
	     char title[50];
	     int yr;
	     char genre[10];
	
public:
		 cd();  // construct a new blank CD.
	     void getdata(void);
	     //void showdata(void);  // probably show data and put data are 
the same thing
								// I sugest that you get rid of this.
	     void putdata(void);
	 };


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

//class cdlib {
	 int main()
	 {
		cd rack[10]; // some place to keep 10 CDs
		
			for(int i=0; i<10; i++)
			{
				rack[i] = new cd();    // create a new CD
				//rack[i].getdata();        // fill it with data
				//rack[i].putdata();        // print out the data to confirm its 
right.
			} // for
		/*for(int i=0; i<10; i++)
		{
			rack[i].putdata();        // print out the data to confirm its right.
		} // for  */
			
		     return 0;
		 } // main

//};
	//********
	
void cd::getdata()
{
		/* get the data from the user and write it down to a text file. use 
cin */
		cout << "Enter the Artist's Name: "<< endl;
		cin.getline >> artist;
		cout << "Enter the Compact Disk Title: " << endl;
		cin.getline >> title;
		cout << "Enter the Year the CD was recorded: "<< endl;
		cin >> yr;
		cout << "Enter the genre for this CD: " << endl;
		cin.getline >> genre;
}

void cd::putdata()
{
	cout << artist << endl;
	cout << title << endl;
	cout << yr << endl;
	cout << genre << endl;
}


On Mar 13, 2004, at 11:52 PM, Kathryn Hogg wrote:

>
> wolf said:
>> this is the current version I'm trying to get working:
>> #include <iostream>
>>   using namespace std;
>>
>> class cd {
>>   private:
>> 	     char artist[30];
>> 	     char title[50];
>> 	     int yr;
>> 	     char genre[10];
>>
>> public:
>> 		 cd();  // construct a new blank CD.
>> 	     void getdata(void);
>> 	     //void showdata(void);  // probably show data and put data are
>> the same thing
>> 								// I sugest that you get rid of this.
>> 	     void putdata(void);
>> 	 };
>>
>>
>> //***********************
>>
>> class cdlib {
>> 	 int main()
>
> I don't think you want main() inside of a class;
>
>
>> 	 {
>> 		cd rack[10]; // some place to keep 10 CDs
>>
>> 			for(int i=0; i<10; i++)
>> 			{
>> 				rack[i] = new cd();    // create a new CD
>
> new is for allocating a object in the heap and it returns a pointer.
>
> In this case that would be "cd *".
>
> When you create the local variable rack above.  the compiler creates an
> array of 10 cd objects and then goes through each one can calls the
> default constructor for it.
>
> So your attempt to initialize rack[i] is unnecessary.
>
>> 				rack[i].getdata();        // fill it with data
>> 				rack[i].putdata();        // print out the data to confirm its
>> right.
>> 			} // for
>> 		for(int i=0; i<10; i++)
>> 		{
>> 			rack[i].putdata();        // print out the data to confirm its 
>> right.
>> 		} // for
>> 		     return 0;
>> 		 } // main
>>
>> };
>> 	//********
>>
>> 	void getdata()
>
> Should be void cd::getdata() since its a member function of class 'cd'
>
>> {
>> 		/* get the data from the user and write it down to a text file. use
>> cin */
>> 		cout << "Enter the Artist's Name: "<< endl;
>> 		cin.getline >> artist;
>> 		cout << "Enter the Compact Disk Title: " << endl;
>> 		cin.getline >> title;
>> 		cout << "Enter the Year the CD was recorded: "<< endl;
>> 		cin >> yr;
>> 		cout << "Enter the genre for this CD: " << endl;
>> 		cin.getline >> genre;
>> }
>>
>> void putdata()
>
> Should be void cd::putdata()
>
>> {
>> 	cout << artist << endl;
>> 	cout << title << endl;
>> 	cout << yr << endl;
>> 	cout << genre << endl;
>> }
>>
>> these are the errors that print out when I try to compile the program
>> from a terminal session:
>> Compiling...
>> cd.cpp:22: warning: all member functions in class `cdlib' are private
>> cd.cpp: In member function `int cdlib::main()':
>> cd.cpp:29: error: no match for `cd& = cd*&' operator
>> cd.cpp:4: error: candidates are: cd& cd::operator=(const cd&)
>> cd.cpp: In function `void getdata()':
>> cd.cpp:47: error: `artist' undeclared (first use this function)
>> cd.cpp:47: error: (Each undeclared identifier is reported only once 
>> for
>>     each function it appears in.)
>> cd.cpp:49: error: `title' undeclared (first use this function)
>> cd.cpp:51: error: `yr' undeclared (first use this function)
>> cd.cpp:53: error: `genre' undeclared (first use this function)
>>
>
> -- 
> Kathryn
> http://womensfootyusa.com
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming
>


More information about the Programming mailing list