0

Here is my code, I was trying to allocate memory to an object by asking size from the user. I dont know where I am going wrong. The error the compiler is giving me is "void value not ignored as it ought to be". Please help me. Thanks in advance.

#include <iostream> using namespace std; class test { char name[20]; char address[30]; char desig[20]; public: void getData(); void display(); ~test() { cout << "Destructor is invoked"; } }; void test::getData() { cout << "Enter your name" << endl; cin >> name; cout << "Enter address" << endl; cin >> address; cout << "Enter designation" << endl; cin >> desig; } void test::display() { cout << "name" << endl; cout << name << endl; cout << "address" << endl; cout << address; cout << "Enter designation" << endl; cout << desig; } int main() { int s; cout << "Enter the size of an array" << endl; cin >> s; test* p1 = new test[s]; for (int i = 0; i < s; i++) { *p1[i].getData(); } for (int i = 0; i < s; i++) { *p1[i].display(); } delete[] p1; return 0; } 

2 Answers 2

1

You need to change:

*p1[i] 

To:

p1[i] 
Sign up to request clarification or add additional context in comments.

Comments

1

Here:

*p1[i].display();

You're calling member function display that returns void and try to dereference that.

1 Comment

+1 Actually the correct answer - to emphasize: *(p1[i].display())

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.