Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Remilia Scarlet

A little assistance is wanted...

Recommended Posts

Given that I haven't done classes in so long in C++, I was wondering:

1. How do I make, and pass to a function, an array of class objects?
2. If I were to make a vector of objects instead, how do I pass these to functions and then call the classes's member functions?

Examples: (assume I have a class called class_queens)

class_queens queens[8];

for(int i = 0; i < 8; i++)
{
    queens[i].set_phone_number(5551212);
    if(is_safe(queens, i, 8)
    {...}
}

or

vector <class_queens> queens[8];

for(int i = 0; i < 8; i++)
{
    queens[i].set_phone_number(5551212);
    if(is_safe(queens, i, 8)
    {...}
}

Obviously, I'm not storing the phone numbers of queens, but just used as an example.
If I use objects, it'd make this damned 8-queen problem alot easier to solve. I could solve it in about 15 minutes in VB.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×