473,837 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.cp p
=============== =============== =============== =============== =
1 #include <iostream>
2 #include <string>
3 #include "file_handler.h "
4 using namespace std;
5 file_handler::f ile_handler()
6 {//file_rd="tmp.da t";
7 //file_wr="tmp.da t";
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_handl er10data_fetchE v (this=<incomple te type>) at
file_handler.cp p: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 2966
Ian
ol********@anal og.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********@anal og.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.cp p
=============== =============== =============== =============== =
1 #include <iostream>
2 #include <string>
3 #include "file_handler.h "
4 using namespace std;
5 file_handler::f ile_handler()
6 {//file_rd="tmp.da t";
7 //file_wr="tmp.da t";
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_handl er10data_fetchE v (this=<incomple te type>) at
file_handler.cp p: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.cp p:21?

-Ramashish

Aug 17 '05 #5

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

Similar topics

6
19286
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 #include<iostream> #include <cstring> #include <cmath>
7
4961
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
5
33758
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 cinstance(binstance); The compiler gives the error,
2
2407
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
2118
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 first line, "warning C4132: 'x' : const object should be initialized" yet generates correct code.
5
2089
by: friend.05 | last post by:
1) #include <stdio.h> #include <stdlib.h> #include "graph.h" #define MAX_VTX 4 struct _graph_vertex {
2
3860
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 = sorted(some_clusters,less_Eccentricity()); I`m trying to pass a function object (less_Eccentricity) into a higher level function that uses it in the call to sort.
50
4531
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): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
7
1538
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 function body), but is declaration and initialization of an integer variable 'func_name', is it step towards completeness of OOP abstraction in the language, here one could say we are creating and initializing an integer object, but then again it (this...
0
9843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7005
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4476
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.