473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

CLASS ?

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

Dec 3 '05 #1
2 1219
tvn007 wrote:
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
Dec 3 '05 #2
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.