By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,128 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,128 IT Pros & Developers. It's quick & easy.

2 Errors!

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a

"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

P: n/a
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

P: n/a
> 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

P: n/a

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

P: n/a


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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.