473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Why do I see an incomplete type when I define the constructor outside the class declaration?

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

Aug 15 '05 #1
4 2941
Ian
ol********@analog.com wrote:
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;
Never do this in a header!

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

Very old compiler and OS version. Why not use a more up to date version?

Ian
Aug 15 '05 #2
> ================================================== ==========
1 #include <string>
2 using namespace std;


Never do this in a header!

-->I remove this from header file but the problem is still exist.
--> Compiler/OS version: My company deploy these for us, Do you think
it's a bug of compiler?

Aug 15 '05 #3

ol********@analog.com wrote:
================================================== ==========
1 #include <string>
2 using namespace std;


Never do this in a header!

-->I remove this from header file but the problem is still exist.
--> Compiler/OS version: My company deploy these for us, Do you think
it's a bug of compiler?


You should not put "using namespace std" into your header in global
scope because then you are forcing anyone who includes your header to
put all of std into the global namespace.

It is not so bad if you declare it inside another namespace (where it
is then limited to that namespace).

However that itself will not be the cause of your error.

Incomplete types are run-time are only a problem in a "delete"
statement because you are allowed to delete an incomplete pointer.
However they might then cause a runtime error if you try to do so.
Otherwise your code should fail to compile and incomplete types cannot
cause runtime errors.

Aug 15 '05 #4
Ram
> ================================================== ===========

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


You haven't mentioned the code at which it is failing. Whats at
file_handler.cpp:21?

-Ramashish

Aug 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Zenon | last post by:
Folks, I cannot figure out why I am getting an error: Error E2303 EngineX.hpp 19: Type name expected. Here is my code. Can you please help? #ifndef EngineX__hpp #define EngineX__hpp ...
7
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
5
by: Lou Pecora | last post by:
g++ compiler error question. I have a container C whose constructor takes a class B that is inherited from an abstract class A. So I have the line of code: B binstance; C ...
2
by: verec | last post by:
Consider a first version: --- drawable.hpp --- #include "gcdata.hpp" struct drawable { ... virtual int internal_new_GC(gcdata * gcd) = 0 ; } ; --- gcdata.hpp ---
24
by: ark | last post by:
Hello group, Could you help me with this: static const int x; ............ something ............. static const int x = 17; It looks perfectly legal to me but MSVC/C++ 6.0 gives, on the...
5
by: friend.05 | last post by:
1) #include <stdio.h> #include <stdlib.h> #include "graph.h" #define MAX_VTX 4 struct _graph_vertex {
2
by: Alan | last post by:
I get a compilation error "parameter 2 of `Clusters sorted(Clusters, func_obj)' has incomplete type `func_obj' " when attempting to compile the following code: some_clusters =...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
7
by: krishna | last post by:
What is the need of this syntax for initializing values, isn't this ambiguous to function call? e.g., int func_name(20); this looks like function call (of course not totally as there is no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.