Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why am I getting an error for \"expected type specifier\" on the line: vector na

ID: 3795592 • Letter: W

Question

Why am I getting an error for

"expected type specifier" on the line: vector name(500);

Here is the code:

#include <iostream>

#include <conio.h>

#include <stdio.h>

#include <vector>

using namespace std;

class addressbook

{

private:

vector<char> name(500);

long ph_num; //class addressType :public addressbook

vector<char> address(500);

int year;

int month;

int day;

char gender;

int d, Th, y;

char M, F, m, f;

// char freind[];

public:

addressbook();

void setName();

void getName();

void getphone();

long setphone();

void setAddress();

void getAddress();

float getAverage();

int setDay();

void getDay();

int setMonth();

void getMonth();

int setYear();

void getYear();

char setGender();

void getGender();

};

Explanation / Answer

#include <iostream>

#include <stdio.h>

#include <vector>

using namespace std;

class addressbook

{

private:

vector<char> name;

long ph_num; //class addressType :public addressbook

std::vector<char> address;

int year;

int month;

int day;

char gender;

int d, Th, y;

char M, F, m, f;

// char freind[];

public:

addressbook(int n = 500) {name.resize(n); address.resize(n);}

void setName();

void getName();

void getphone();

long setphone();

void setAddress();

void getAddress();

float getAverage();

int setDay();

void getDay();

int setMonth();

void getMonth();

int setYear();

void getYear();

char setGender();

void getGender();

};

int main(){

}
===========================================================================================

You cannot initialize a class member that way, either you have to do using constructors or functions

As you can see, I have Resized them /u can initalise as well but both will reuire a constructor or function.


Thanks, let me know if there is any concern.