CLASS ?

T

tvn007

Could someone please help me or point/explain to me why the error in
line 46 ?

////////////////////////Error message:////////////////////////////////

bash-2.05b$ g++ test3.cpp
test3.cpp: In function `int main()':
test3.cpp:46: error: request for member `print_data' in `ptrstudent',
which is
of non-aggregate type `Record_info*'
//////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX=50;
typedef double Number;
class Record_info {
public:
string bypassed;
string name;
int midterm;
Number quiz;
//double quiz;
Number final;
string testname;
void print_data();
};
void Record_info:: print_data(){
cout <<"name is : "<<name<<endl;
cout <<"Midterm is : "<<midterm<<endl;
cout <<"Quiz is : "<<quiz<<endl;
cout <<"Final is : "<<final<<endl;
cout <<"Testname is : "<<testname<<endl;
}

int main (void){
Record_info student[MAX],*ptrstudent;
ptrstudent = student;
ifstream in ("test2.txt");
string line;
string line2;
char buffer[40];
while (getline(in,line)){
if (line.find("#")!=string::npos)continue ;
istringstream stringstreams(line);

stringstreams>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;
stringstreams>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;
ptrstudent++;
}

for (ptrstudent=student; ptrstudent->midterm;ptrstudent++){
if (ptrstudent->bypassed.find("Y")!=string::npos)continue ;
double test= ptrstudent->quiz +100;
cout << "test is : "<<test<<endl;
ptrstudent.print_data(); //line 46
stringstream stream,stream2;
stream << "Do Add Bonus: "<<ptrstudent->name <<" "
<<ptrstudent->quiz;
string task(stream.str());
cout << task << endl;

stream2 <<"Do ExtraCredit: "<<ptrstudent->name<<" :"
<<ptrstudent->final<< " has done extra credit " <<ptrstudent->final+5;
string task2(stream2.str());
cout <<task2<<endl;
}

return 0;
}


//////////////////////////input file:
test2.txt//////////////////////////

###
Y Tony 90 -15.2 98.2 math
N Michael 95 17.2 92.2 physics
N Amy 82 13.9 78.2 accounting
 
V

Victor Bazarov

tvn007 said:
Could someone please help me or point/explain to me why the error in
line 46 ?

////////////////////////Error message:////////////////////////////////

bash-2.05b$ g++ test3.cpp
test3.cpp: In function `int main()':
test3.cpp:46: error: request for member `print_data' in `ptrstudent',
which is
of non-aggregate type `Record_info*'
//////////////////////////////////////////////////////////////////////////////////////////////////
[...]
int main (void){
Record_info student[MAX],*ptrstudent;

So, 'ptrstudent' is a _pointer_...
[...]
ptrstudent.print_data(); //line 46

Pointers do not have members themselves. If you need to access a member
of a class to which the pointer points, you need to use '->' ("arrow")
operator:

ptrstudent->print_data();

This is really a very basic stuff, I am surprised you needed to summon
the help of a newsgroup for that.

V
 
A

Alf P. Steinbach

* tvn007:
Could someone please help me or point/explain to me why the error in
line 46 ?
ptrstudent.print_data(); //line 46

Presumably this is your own code.

And if it is, ask yourself why you put the three characters 'ptr' at the
front of the name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help on istream& operator ? 2
struct ? 5
Help on struct ? 3
CIN Input #2 gets skipped, I don't understand why. 1
Array size ? 6
read data from file into structure ? 2
Help, read input from file ? 3
Class Help 11

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top