473,385 Members | 1,535 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,385 software developers and data experts.

2 Errors!

Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two
errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.

/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James

Jul 27 '05 #1
6 1206

"James P. Martin" <pr**************@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two
errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.

/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James


Hi

The member variable "data" has to be public and comment out the line "p.data
= 10;" because p is a pointer. Use "p->data" or "(*p).data".

Greetings Chris
Jul 27 '05 #2
On 27 Jul 2005 00:45:03 -0700, James P. Martin
<pr**************@gmail.com> wrote:
Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two
errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
p is a _pointer_to_ a structure, or class in this case, and not a
structure.

Error D:\1.cpp 18 list::node::data is not accessible.
data is a private attribute of class node (class members
(attributes/methods) are private by default)


/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James


Jul 27 '05 #3
> Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.


You have on line 17 & 18:
p.data=10;
p->data=10;

p is a pointer. That means it contains the adress of an object of the
type node. It is not an object of the type node. Because of that if you
try to do
p.data=10; you get the the first error since p has no data member.

For the second error. A class has as default that anything declared in
it is private. A struct has as default that anything declared in it is
public. You might want to change class node to struct node to get rid
of that second error.

Jul 27 '05 #4

Thanks Chris for the quick response.
Regards
James
Christian Meier wrote:
"James P. Martin" <pr**************@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two
errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.

/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James


Hi

The member variable "data" has to be public and comment out the line "p.data
= 10;" because p is a pointer. Use "p->data" or "(*p).data".

Greetings Chris


Jul 27 '05 #5


Christian Meier wrote:
"James P. Martin" <pr**************@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two
errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.

/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James

Hi

The member variable "data" has to be public and comment out the line "p.data
= 10;" because p is a pointer. Use "p->data" or "(*p).data".
Hello Chris

After making "data" pubic I am still getting Error 18.Please Help. Greetings Chris


Jul 27 '05 #6
"James P. Martin" <pr**************@gmail.com> schrieb im Newsbeitrag
news:11*********************@g43g2000cwa.googlegro ups.com...


Christian Meier wrote:
"James P. Martin" <pr**************@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi to all,
I am sorry if the question is off topic.
But I am trying to learn c++ and in the following code I am getting two errors using TurboC++ compiler 3.0

Error D:\1.cpp 17 structure reqired on left of . or .*
Error D:\1.cpp 18 list::node::data is not accessible.

/********code***********/

#include<iostream.h>
class list

{
private :
class node
{
int data;
node *link;
}*p;

public :
void create()
{
p=new node;
p.data=10;
p->data=10;
}
};
int main()
{
list l1;
l1.create();
return 0;
}
Could anybody please tell me why these errors are there and how to
remove.
With Regards
James


Hi

The member variable "data" has to be public and comment out the line "p.data = 10;" because p is a pointer. Use "p->data" or "(*p).data".
Hello Chris

After making "data" pubic I am still getting Error 18.Please Help.


Do you have

class node
{
public:
int data;
node *link;
}*p;

This should work. My compiler compiles after this changes.

BTW #1: Learn to help yourself with the compiler hints. First try to fix
your error. When you really can't solve the problem, then you can write to
the NG.
BTW #2: This is a NG for standard c++, do not use #include <iostream.h>
Jul 27 '05 #7

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

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
2
by: Trev | last post by:
SQL Server 2000 BE, Access 2002 FE. I want to write a stored procedure, that will among other things log errors to a table, I want to be able to report a summary of work done and errors to the...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
2
by: Samuel R. Neff | last post by:
Within the past few weeks we've been getting a lot of compiler errors in two classes when no errors actually exist. The error always reports as Name '_stepResizeRelocator' is not declared. ...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
0
by: clemrock | last post by:
Help w/ errors.add_to_base between controller and model Hello, I'm having trouble in routing some errors between model and controller. The errors produced in the controller...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.