473,748 Members | 4,178 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 2960
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
19274
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
4955
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
5
33676
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
2403
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
2101
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
2082
by: friend.05 | last post by:
1) #include <stdio.h> #include <stdlib.h> #include "graph.h" #define MAX_VTX 4 struct _graph_vertex {
2
3855
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
4492
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
1536
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
8987
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
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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,...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
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
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
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.