May 8, 2013 at 3:07pm UTC
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 May 8, 2013 at 3:10pm UTC
May 8, 2013 at 3:13pm UTC
Probably file containg main() isn't included in compile list.
May 8, 2013 at 3:22pm UTC
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 May 8, 2013 at 3:23pm UTC
May 8, 2013 at 3:26pm UTC
Constructors must have the same name as the class name.
You have just created a function with the name constructor.
May 8, 2013 at 3:28pm UTC
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 May 8, 2013 at 3:28pm UTC
May 8, 2013 at 4:05pm UTC
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 May 8, 2013 at 4:06pm UTC
May 8, 2013 at 4:21pm UTC
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.
May 8, 2013 at 5:09pm UTC
It is a method, so it should be applied to an instance of sudoku class.
May 8, 2013 at 5:49pm UTC
can you clarify? or explain? i dont see what i'm doing wrong in my book
Last edited on May 8, 2013 at 5:49pm UTC
May 8, 2013 at 9:53pm UTC
edit: figured this one out
Last edited on May 8, 2013 at 10:09pm UTC