Loading a vector class

Here is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <istream>
#include <string>
#include <vector>
using namespace std;

class dm_energy_vec
{
public:
	vector<float> m_energy_dep;
};

int main()
{
	const int phantom_size = 50; 
	int energy_index;
	vector<float> xpos;
	vector<float> energy;
	vector<float> energy_dep (0, phantom_size);
	vector<dm_energy_vec> energy_dep_sum;

// Create two vectors: xpos and energy. 
	for(int i = 0; i < 25; i++)
		xpos.push_back(0.325*i); 

	for(int i = 0; i < 25; i++)
		energy.push_back(5.364*i); 

//create another vector, energy_index that contains the ceiling values of xpos 
	for(int i = 0; i < 25; i++)
	{
		energy_index = ceil(xpos.at(i));
		//use the energy_index values as the index for another vector, energy_dep, which stores the energy values
		energy_dep.at(energy_index) = energy.at(i);

	//store each energy_dep vector in energy_dep_sum vector which is defined by a class
		energy_dep_sum.push_back(energy_dep);

	}

};


This program first creates two vectors: xpos and energy. xpos and energy contain floating point values. Next, the energy_index vector is created which contains the ceiling values of the xpos vector. Next, the vector, energy_dep, is created which contains the energy values at index, energy_index. What I am trying to do is to store each energy_dep vector into the energy_dep_sum vector using the class dm_energy_vec. When I try to compile this program there is an error on line 40 which reads the following:

Error 4 error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'dm_energy_vec &&'

Does anybody know what the problem is with my code?
Like it says. energy_dep is a vector, while in energy_dep_sum you can only push dm_energy_vec objects.
The long solution is
1
2
3
dm_energy_vec tmp;
tmp.m_energy_dep = energy_dep;
energy_dep_sum.push_back( tmp );

The short one is to write a constructor.

Also, you have wrong vector constructor arguments (line 22). They are number, value, not the other way. Now you have 0 elements initialized to 50.
Topic archived. No new replies allowed.