O
oliver.lin
In my simple test code, I tried to define my constructor outside of the
class declaration headr file.
The header file: file_handler.h
============================================================
1 #include <string>
2 using namespace std;
3 class file_handler
4 { //Declare member variables
5 private:
6 string file_rd, file_wr; //Define the file name for read
and write.
7 string name[100]; //Define a string array without
pre-defined size.
8 float score[100]; //The score corresponding to the name.
9 public:
10 file_handler();
11 //Constructor, Initialize the default file name.
=============================================================
The function definition: file_handler.cpp
=============================================================
1 #include <iostream>
2 #include <string>
3 #include "file_handler.h"
4 using namespace std;
5 file_handler::file_handler()
6 {//file_rd="tmp.dat";
7 //file_wr="tmp.dat";
8 score[0]=0;
9 }//Default constructor
==============================================================
The compile with g++ -Wall -g is OK. But when I debug the program and
step into the member function of the file_handler, I saw the following
complain from gdb:
===============================================================
(gdb) step
(gdb) step
_ZN12file_handler10data_fetchEv (this=<incomplete type>) at
file_handler.cpp:21
(gdb)
===============================================================
With the incomplete type of "this" pointer, I can't watch the member
variables of the object. But strangely enough, all the member variables
can be assgined value coorectly.
When I put the constructor definiton in the header file or just remove
this definition, this point gets it value and I can see any variable
from GDB.
I wonder is the problem from my program or from the g++/gdb.
My paltform: solaris 2.6
Compiler g++2.95/gcc 2.95
Debugger: gdb4.16
class declaration headr file.
The header file: file_handler.h
============================================================
1 #include <string>
2 using namespace std;
3 class file_handler
4 { //Declare member variables
5 private:
6 string file_rd, file_wr; //Define the file name for read
and write.
7 string name[100]; //Define a string array without
pre-defined size.
8 float score[100]; //The score corresponding to the name.
9 public:
10 file_handler();
11 //Constructor, Initialize the default file name.
=============================================================
The function definition: file_handler.cpp
=============================================================
1 #include <iostream>
2 #include <string>
3 #include "file_handler.h"
4 using namespace std;
5 file_handler::file_handler()
6 {//file_rd="tmp.dat";
7 //file_wr="tmp.dat";
8 score[0]=0;
9 }//Default constructor
==============================================================
The compile with g++ -Wall -g is OK. But when I debug the program and
step into the member function of the file_handler, I saw the following
complain from gdb:
===============================================================
(gdb) step
(gdb) step
_ZN12file_handler10data_fetchEv (this=<incomplete type>) at
file_handler.cpp:21
(gdb)
===============================================================
With the incomplete type of "this" pointer, I can't watch the member
variables of the object. But strangely enough, all the member variables
can be assgined value coorectly.
When I put the constructor definiton in the header file or just remove
this definition, this point gets it value and I can see any variable
from GDB.
I wonder is the problem from my program or from the g++/gdb.
My paltform: solaris 2.6
Compiler g++2.95/gcc 2.95
Debugger: gdb4.16