|
-
May 31st, 2008, 02:05 PM
#1
Vector problem
I have problem with adding object into vector
her's the code
#include <iostream>
#include <vector>
using namespace std;
class Pair {
public:
Pair(int a, int b)
{x=a; y=b;};
int get_x()
{return x;};
int get_y()
{return y;};
private:
int x;
int y;};
int main()
{vector<Pair> set();
Pair* a1 = new Pair(70, 64);
set.push_back(a1);
system("PAUSE");
return 0;
}
and i get only error message :S
pls some help
-
May 31st, 2008, 02:12 PM
#2
Re: Vector problem
You have a vector<Pair>, not a vector<Pair*>, so you should write:
Code:
vector<Pair> set;
set.push_back(Pair(70, 64));
Okay, actually, I lied. This declares a function named set that takes no arguments and returns a vector<Pair>:
Code:
vector<Pair> set();
but I inferred that you actually wanted a vector<Pair> named set, and thus suggested the change accordingly.
By the way, the C++ standard library already has std::pair.
-
May 31st, 2008, 03:31 PM
#3
Re: Vector problem
Flixter, do not call your variable "set". There already is a std::set container, and calling your variables the same as standard classes will just confuse you and/or the compiler.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|