Class related short question

How do you write a vector called from a class, inside another function called from a class? It says intVectorOne is undefined...

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
  class Board 
{
public:
	void Solve();
private:
        vector<int> intVectorOne(N); /*where N is user defined, somewhere else in my program)*/ 
        int is_valid();
}

int is_valid()
{
for (int i = 0; i < N-1; i++) 
	{
		for (int j = i + 1; j < N; j++) 
		{
			if (intVectorOne[i]=intVectorOne[j]//ERROR: Identifier 'intVectorOne' is undefined.
                         {/*stuff*/}
	        }
	 }
}



void Board::Solve()
if(is_valid())
{
//stuff
}
Last edited on
The definition of is_valid defines a standalone function. Compare the syntax to Board::Solve(), which clearly defines a member of Board.

Is it really safe to use 7 and 8, if N is something random?
You're right, I was assuming N to be '8'. I changed it. I'll try to imitate the syntax, thanks.
Changed is_valid() to int Board::is_valid() Now I get the error:

function call missing argument list; use '&Board::intVectorOne' to create a pointer to member

And

Apparently, my
vector<int> intVectorOne(N); has the error:
syntax error : identifier 'N'

This is so hard... T_T
Last edited on
Erhm... the problem solved itself, I don't know why or how... thanks guys...? :/
Compiler thinks that line 6 is a member function declaration. Initialize the vector in constructor.

Definition of class ends with a semicolon (line 8).
Line 8 was correct in my program, it was only a mistake here, as for line 6, what do you mean "Initialize the vector in constructor."?
Board is a class. Classes have constructors. Constructor initializes an object when the object is created. Part of initialization is the creation of the member variables. Read about class member initializer lists.
Topic archived. No new replies allowed.