Hello! I'm fairly new to computer science, and I'm working on a program that holds a database in a vector. The data type for the vector though is defined as a class.

My header file has this in it:

class problem {

private:
	string name; //Name of person with the problem
	string cost; //How it'll cost to fix the problem
	string helper; //Name of person helping solve the problem

public:
	problem (string a_name, string a_cost, string a_helper);

The .cpp file that goes with this header has this:

#include "problem.h"

problem::problem (string a_name, string a_cost, string a_helper) {
	name = a_name;
	cost = a_cost;
	helper = a_helper;
}

But now I'm having trouble defining a vector in the main.cpp part of my program.

What I want is something like:

string person;
string value;
string assistant;

vector <problem> problems.push_back(person, value, assistant);

Note: person, value, and assistant change multiple times with my program.

This code won't work though. Any help I could get to fix this problem would be most appreciated.

Thank you.

you don't declare it like that. First just declare the vector object vector <problem> problems; . Then later on you can add classes to it

vector <problem> problems;
problem person;

for(;;)
{
    // enter each of the attributes of the person object is not shown

    // add a class object to the vector
    proglems.push_back(person);
}

call the constructor explicitly to create a new temporary object

problems.push_back(problem(person, value, assistant));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.