Using pointers

first off, i looked at alot of posts with pointer information, none of which i saw to help. Here is what i have

i have a file mp4.h that contains
1
2
3
4
5
6
7
class MPClass
{
 public:
  //member functions here
 private:
  MediaClass *ptr;
}


then i have media4.h which has MediaClass in it..

I also have p4.cpp which calls my functions.. but in my mp4.cpp i am calling funtions through pointers.. ex.

ptr->SetMedia(string title);

it is giving me an error saying in mp4.cpp undefined reference to SetMedia

i can not figure this out.. any suggestions?
You're probably not linking media4.cpp with p4.cpp. Compiler?
oh oops.. thats when i get my error. forgot to say that. when i link them.. i am using a compiler called Joe? its on school comps on a linux system
Last edited on
There's no such thing.
IIRC, Joe is a text editor used mainly in Linux, so you're using GCC. I have no experience with that editor, but try using this command line:
g++ p4.cpp media.cpp (any other files you're using)
I am not sure .. i type joe mp4.h to open up the editor. so i guess that makes sense..

i type c++ p4.cpp -c
that just compiles
then mp4.cpp -c


then c++ mp4.o p4.o -o mp4.exe which links them into an exe that i run... thats where i get my error

so it must a linking error.. >.>

edit..... i tried g++ p4.cpp mp4.cpp .... it filled my screen for like 3 seconds with just a whole bunch of jargon
Last edited on
"a whole bunch of jargon" doesn't mean anything to me.
alright.. uhh stuff like this

stream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linxu/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:102: note:

and it repeats like.. 500 times

towards thebottm it says p4.cpp:85: erro: class MPClass has no member named SetKey

and it goes through every function i have like 3 times
Hmm... It's possible you're missing a semicolon somewhere. This kind of senseless errors is a common symptom of that. Post your headers, first.
Last edited on
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
// mp4.h

#ifndef _MPH
#define _MPH

#include <iostream>
#include <fstream>
#include <iomanip>
#include "media4.h"

using namespace std;


class MPClass
{
  public:
    MPClass( );
    // default constructor
    // Sets the member data so that no MediaClass is allocated
        
    MPClass(const MPClass& copy);
    // Copy Constructor
    // Sets the member data to have its own copy
    // of the MPClass passed in
    
    ~MPClass( );
    // Deallocates the member data if allocated
    
    MPClass& operator=(const MPClass & copy);
    // Assignment operator
    // Deallocates current member data
    // Sets member data to have its own copy 
    // of the MPClass passed in
    
    void SetMedia(string title, int seq, string rating, int qty);
    // Sets the member data if valid
    // Pre:  parameters must have values
    // Post: valid parameters - member data is set to parameter values 
    //	    return true
    //       invalid - member data unchanged
    //          return false

    void SetKey(string title, string type);
    // Sets the member key data
    // Pre:  parameters must have a value
    // Post: valid parameters - title & seq num is set to parameter values 
    //	    return true
    //       invalid - member data unchanged
    //          return false


    string ReturnTitle( ) const;
    // Returns the title
    // Pre:  member data must have value
    // Post: returns title of item to the caller
          
    MediaType ReturnType( ) const;
    // Returns the Media Type (VHS, DVD, ...)
    // Pre:  member data must have value
    // Post: returns type of item to the caller
                
    MediaKindType ReturnKind( ) const;
    // Returns the kind of media (ACTION, DRAMA...)
    // Pre:  member data must have value
    // Post: returns kind of item to the caller
        
    MediaRatingType ReturnRating( ) const;
    // Returns the rating type (NR, G, PG...)
    // Pre:  member data must have value
    // Post: returns rating of item to the caller
        
    int ReturnQty( ) const;
    // Returns the qty
    // Pre:  member data must have value
    // Post: returns qty of item to the caller
            
    void UpdateQty(int addQty);
    // Updates the qty of the item by adding the additional qty
    //  if addQty is negative then qty is reduced
    // Pre:  member data must have value
    // Post: qty of the item has been updated by the addqty

    bool EqualTitle(const MPClass& m) const;
    // returns whether two titles are equal
    // Compares two media classes based on the title
    // Pre:  member data must have a value
    // Post: Returns true if the titles are the same, false otherwise
    //       Not case sensitive (ie Shrek == SHREK == shrek)

    // Relational operators use key: title & type
    bool operator==(const MPClass& m) const;
    bool operator!=(const MPClass& m) const;
    bool operator<(const MPClass& m) const;
    bool operator<=(const MPClass& m) const;
    bool operator>(const MPClass& m) const;
    bool operator>=(const MPClass& m) const;


    friend ostream& operator<<(ostream& out, const MPClass & m) ;
    // friend function for output
    // Pre: Data members in MediaClass m have a value
    //      ostream must have  value
    // Post: All data members in MediaClass m have been inserted into
    //           ostream.  ostream is returned.
                                                          
                                                          


  private:
    MediaClass *ptr;
    MediaClass media;
};

#endif
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// media4.h


#ifndef _MEDIA4
#define _MEDIA4


#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;


//******************************************** RateType *****
enum MediaRatingType {NR, G, PG, PG13, R, X};


string RatingToStr( MediaRatingType rating);
// Converts the MediaRatingType to string
// pre: rating has a value
// post: returns a string based on the rating

MediaRatingType StrToRating( string rating);
// Converts the str to MediaRatingType 
// pre: rating has a value
// post: returns rating based on the string


//******************************************** MediaType *****
enum MediaType {ERR_TYPE, VHS, DVD, GAME};

MediaType FindType(int seqNum);
// Determines the type of item from the sequence number
// Pre:  seqNum must have a positive value from 1 - 1000
// Post: the type is determined from the seqNum and returned to caller

string MediaToStr( MediaType t);
// Converts the MediaType to string
// pre: t has a value
// post: returns a string based on t


//******************************************** MediaKindType *****
enum MediaKindType {ERR_KIND, ACTION, DRAMA, HORROR, 
		    SCIFI, COMEDY, 
		    SUSPENSE, FAMILY};

MediaKindType FindKind(int seqNum);
// Determines the kind of item from the sequence number
// Pre:  seqNum must have a positive value from 1 - 1000
// Post: the kind is determined from the seqNum and returned to caller


string KindToStr( MediaKindType kind);
// Converts the MediaKindType to string
// pre: kind has a value
// post: returns a string based on the kind



//******************************************** MediaClass *****
class MediaClass
{
	public:

		MediaClass( );
		// default constructor
		// Sets the initial values of the member data
		
		bool SetMedia(string title, int seq, string rating, int qty);
		// Sets the member data if valid
		// Pre:  parameters must have values
		// Post: valid parameters - member data is set to parameter values 
		//	    return true
		//       invalid - member data unchanged
		//          return false
		
		bool SetKey (string title, string type);
		// Sets the title and seq num (based on type) for the media item
		// Pre:  parameters must have a value
		// Post: valid parameters - title & seq num is set to parameter values 
		//	    return true
		//       invalid - member data unchanged
		//          return false
		
		void InputMedia( );
		// Gets the valid data member values for a 
                //      MediaClass from standard input
                // pre: none
                // post: data members of MediaClass have valid values
                      		
		void ReadMedia(istream &input);
		// Gets the member data from an input stream
		// record format: title#seqnum#rating#qty
		// Pre:   input stream must be open
		// Post:  media member data has been extracted from the stream
				
		void DisplayMedia(ostream& output) const;
		// Prints the member data to an output stream
		// record format: title  type  kind  rating  qty
		// Pre:  output stream must be open
		//	 member data must have value
		// Post: media member data has been inserted into the stream
		
		void WriteMedia(ostream &output) const;
		// Outputs the member data to an output stream
		// record format: title#seqnum#rating#qty
		// Pre:  output stream must be open
		//       member data must have values
		// Post: media member data has been inserted into the stream
		
		string ReturnTitle( ) const;
		// Returns the item title
		// Pre:  member data must have value
		// Post: returns title of item to the caller
		
		MediaType ReturnType( ) const;
		// Returns the item type based on the sequence number
		// Example: VHS, DVD, GAME
		// Pre:  member data must have value
		// Post: returns type of item to the caller
		
		MediaKindType ReturnKind( ) const;
		// Returns the item kind based on the sequence number
		// Example: ACTION, DRAMA, HORROR, SCIFI, COMEDY, SUSPENSE, FAMILY
		// Pre:  member data must have value
		// Post: returns kind of item to the caller
		
		MediaRatingType ReturnRating( ) const;
		// Returns the item rate
		// Example: G, PG, PG13, R, X
		// Pre:  member data must have value
		// Post: returns rating of item to the caller
		

		int ReturnQty( ) const;
		// Returns theqty of the item
		// Pre:  member data must have value
		// Post: returns qty of item to the caller
		
		
		void UpdateQty(int addQty);
		// Updates the qty of the item by adding the additional qty
		//  if addQty is negative then qty is reduced
		// Pre:  member data must have value
		// Post: qty of the item has been updated by the addqty
		
		bool EqualTitle(MediaClass media) const;
		// Compares two media classes based on the title
		// Pre:  member data must have a value
		// Post: Returns true if the titles are the same, false otherwise
		//       Not case sensitive (ie Shrek == SHREK == shrek)

		// relational operators use key: title & type
		
       		bool operator==(const MediaClass & media) const;
        	// Compares this MediaClass object with media for equality
        	// Pre: Both class objects have value
      	  	// Post:
        	//     function value = true if the objects are equal
        	//                      false otherwise

        	bool operator!=(const MediaClass & media) const;
        	// Compares this MediaClass object with media for inequality
        	// Pre: Both class objects have value
        	// Post:
        	//     function value = true if the objects are not equal
        	//                      false otherwise

       		bool operator<=(const MediaClass & media) const;
        	// Compares this MediaClass object <= media
        	// Pre: Both class objects have value
        	// Post:
        	//     function value = true if this object <= media
        	//                      false otherwise

        	bool operator>=(const MediaClass & media) const;
        	// Compares this MediaClass object >= media
        	// Pre: Both class objects have value
        	// Post:
        	//     function value = true if this object >= media
        	//                      false otherwise

        	bool operator<(const MediaClass & media) const;
        	// Compares this MediaClass object < media
        	// Pre: Both class objects have value
        	// Post:
        	//     function value = true if this object < media
        	//                      false otherwise

        	bool operator>(const MediaClass & media) const;
        	// Compares this MediaClass object > media
        	// Pre: Both class objects have value
        	// Post:
        	//     function value = true if this object > media
        	//                      false otherwise


	        friend istream& operator>>(istream& in, MediaClass& m);
        	// friend function for input
        	// Pre: istream must have a value
        	// Post: Data members in MediaClass m will have a value
        	//     istream is returned.

	        friend ostream& operator<<(ostream& out, const MediaClass& m);
        	// friend function for output
         	// Pre: Data members in MediaClass m have a value
         	//      ostream must have  value
         	// Post: All data members in MediaClass m have been inserted into
         	//           ostream.  ostream is returned.
		

   private:
   	string title;		// title of the media item
   	int seqNum;		// seq number of the media item
	MediaRatingType rating; // media rating
   	int qty;		// qty of media item

};

#endif


sorry about the length.. haha
try deleting the .gch files that may have formed in the folder where you have saved these files
I tried deleting the .gch files... i still get the same error... undefined reference -_-. Does anybody else know?
Topic archived. No new replies allowed.