Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
class students
{
	char *stud_name;
	int rollno;
public:
	void set_values(char *n,int y)
	{
		stud_name=n;
		rollno=y;
	}
};
int main()
{
	char *name;
	int roll;
	int a;
	cout<<"enter the number of students";
	cin>>a;
	students *ptr=new students[a];
	for(int i=0;i<10;i++)
	{
		cout<<"enter the name and rollno of "<<i<<"th student";
		cin.get(name,20);
		cin>>roll;
		*(ptr+i)->set_values(name,roll);//here is the error
	}
        return 0;
}
Posted
Updated 27-Jun-13 10:13am
v2
Comments
CPallini 27-Jun-13 15:50pm    
Sorry, without knowing the context I cannot help (for instance how is declared ptr?).

You're dereferencing a pointer, then trying to use it as a pointer.

C++
*(ptr+i)->set_values(name,roll);//here is the error



Change to...
C++
(ptr+i)->set_values(name,roll);
 
Share this answer
 
Comments
lewax00 27-Jun-13 18:57pm    
Exactly. +5
H.Brydon 27-Jun-13 23:04pm    
Good answer. The more conventional version of this code would be:

ptr[i]->set_values(name,roll);
Stefan_Lang 28-Jun-13 3:49am    
Indeed. In case this wasn't clear to the OP, the line in question is equivalent to:
*( (ptr+i)->set_values(name,roll) );
and since set_values() returns void, he was dereferencing void. No wonder there was a big bang ;-)
bhawin parkeria 28-Jun-13 8:40am    
thnx a lot jackdingler
Your code doesn't give enough information to be able to say exactly where the problem is, but C2100 is saying that you are using a non-pointer as a pointer. With the code segment you provide here there are several possibilities.

Microsoft's explanation can be found here[^].
 
Share this answer
 
Comments
bhawin parkeria 27-Jun-13 16:27pm    
i have updated the question,
can anyone please tell now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900