When writing a program that uses separate compilation (I have a header file, a .cpp file that declares all the member functions of the class in thee .h file, and an application file). I used a constructor to pass the contents of a dynamic array to a vector, but it is not passing properly.
Here is the constructor: (everything is declared properly, the constructor is a member of the class NumberSet)
NumberSet::NumberSet(int array1[])
{
for (int e=0; e < array_size_horizontal; e++)
{
v1.push_back(array1[e]);
}
}
The constructor is supposed to be used during the main function, but I can't get it to call properly. I also cannot get the array to be passed properly, though theses problems may be one and the same. Here is the declaration of the main function:
int main()
{
int next;
int horcounter = 0;
int nextcounter = 0;
int *array1;
NumberSet runonce;
cout << "Please enter the quantity of integers you will enter: ";
cin >> runonce.array_size_horizontal;
array1 = new int[runonce.array_size_horizontal];
cout << "Please enter " << runonce.array_size_horizontal << " integers, then press return: ";
while (cin >> next)
{
nextcounter++;
array1[horcounter++] = next;
if (nextcounter > runonce.array_size_horizontal-1)
{
break;
}
}
NumberSet constructorcall()//I can't figure out what goes here
return 0;
}
Also, when I have everything in one file, everything else compiles properly, but when they are in their seperate files, I get an error from the header file (below):
//File Name: SSassg1.h
#ifndef SSASSG1_H
#define SSASSG1_H
class NumberSet
{
public:
void add (int A); //adds an element to the set if not already present
void remove (int A); //removes an element from the set if present
void clear(); //clears the set if there are elements present
int size(); //returns the number of elements in the set
void output(); //outputs all elements properly
NumberSet(int array1[]); //transfers the data from an array to a vector
NumberSet( ); //default constructor
int array_size_horizontal;
private:
vector<int> v1;
int vectorsize;
};
#endif //SSASSG1_H
I get an error that says: "ISO C++ forbids declaration of `vector' with no type" (line 18). Also in Line 18, it says "expected `;' before '<' token". I don't know why it won't take this. Any ideas?