have an error i cant figure out

so i have three files and i'm getting an error when i compile and can't figure it out

this is my .h file with my class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;



class sudoku
{
 private:
  int row;
  int col;
  int game[][9];

 public:
  void initialize();
  void readNumbersIn();
};//end class 


this is my main function but i'm not calling any tasks yet
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>
#include <fstream>
#include "homework13.h"
using namespace std;

int main()
{


  return 0;
}


this is my .C file with all my functions in it
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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include "homework13.h"
using namespace std;


void sudoku::initialize()
{
  int row=9;
  int col=9;
  int game[row][col];
}


void sudoku::readNumbersIn()
{

  ifstream fin;
  fin.open("input.dat");

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          fin >> game[row][col];
        }
    }

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          cout << game[row][col]  << "  ";
        }
      cout << endl;
    }

}//end void readNumbersIn 


my error is:

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

Last edited on
Probably file containg main() isn't included in compile list.
Ok was making a mistake on my constuctor but now i'm getting a new error:

.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;



class sudoku
{
 private:
  int row;
  int col;
  int game[][9];

 public:
  constructor(int=0, int=0, int[][9]);
  void readNumbersIn();
};//end class 


.C functions file
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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include "homework13.h"
using namespace std;


sudoku::constructor(int a, int b, int [a][b])
{
  row=a;
  col=b;
  game[a][b];
}


void sudoku::readNumbersIn()
{

  ifstream fin;
  fin.open("input.dat");

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          fin >> game[row][col];
        }
    }

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          cout << game[row][col]  << "  ";
        }
      cout << endl;
    }

}//end void readNumbersIn 


error:

homework13.h:17: error: ISO C++ forbids declaration of âconstructorâ with no type
homework13.h:17: error: default argument missing for parameter 3 of âint sudoku::constructor(int, int, int (*)[9])â

the problem is i thought that constructors aren't supposed to have a type? It didnt in my last program
Last edited on
Constructors must have the same name as the class name.
You have just created a function with the name constructor.
closed account (z05DSL3A)
1
2
3
4
5
6
sudoku::sudoku(int a, int b, int [a][b])
{
  row=a;
  col=b;
  game[a][b];
}
would be the constructor
class sudoku
{
private:
int row;
int col;
int game[][9];

public:
constructor(int=0, int=0, int[][9]);
void readNumbersIn();
};//end class


There is a problem here in the line after public:

First of all constructor name is same as the name of class, in this case it will be

sudoku(int=0, int=0, int[][9]);

Second, If you want to use a member function named "constructor" then you should give it a return type, in your case it will be

void constructor(int=0, int=0, int[][9]);
Last edited on
i'm getting all these errors that i've never encountered before =[
new error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


[code]
class sudoku
{
 private:
  int row;
  int col;
  int game[9][9];

 public:
  sudoku(int=0, int=0, int[][9]);
  void readNumbersIn();
};//end class 


error:

homework13.h:17: error: default argument missing for parameter 3 of âsudoku::sudoku(int, int, int (*)[9])â

Last edited on
You cannot have arguments with default values before arguments without one. Either get rid of =0 in your constructor, or move your array to the beginning.
Ok new error

.h file
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
45
46
47
48
49
50
51
52
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;



class sudoku
{
 private:
  int row;
  int col;
  int game[9][9];
  ifstream fin;

 public:
  sudoku();
  void readNumbersIn();
};//end class

sudoku::sudoku()
{
  row=0;
  col=0;
}//end constructor



void sudoku::readNumbersIn()
{

  ifstream fin;
  fin.open("input.dat");

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          fin >> game[row][col];
        }
    }

  for(int i=0; i<row; i++)
    {
      for(int j=0; j<col; j++)
        {
          cout << game[row][col]  << "  ";
        }
      cout << endl;
    }

}//end void readNumbersIn 


.C file
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <iomanip>
#include <fstream>
#include "homework13.h"
using namespace std;

int main()
{
  readNumbersIn();

  return 0;
}


error:
homework13.C:9: error: âreadNumbersInâ was not declared in this scope

It is a method, so it should be applied to an instance of sudoku class.
can you clarify? or explain? i dont see what i'm doing wrong in my book
Last edited on
1
2
3
4
5
int main()
{
  sudoku x;
  x.readNumbersIn();
}
edit: figured this one out
Last edited on
Topic archived. No new replies allowed.