473,320 Members | 2,027 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,320 software developers and data experts.

How to fix the following problem?

-----------------------Lab002.h------------------------------
#ifndef _LAB_002_
#define _LAB_002_

class base{
char *msg;
public:
base(char *);
~base();
void print(void);
};

class derived1 : base{
public:
derived1(char *);
~derived1();
};

class derived2 : derived1{
public:
derived2(char *);
~derived2();
};
#endif

----------------------------main.cpp------------------------------
#include <iostream>
#include "Lab002.h"
using namespace std;

void main(void){
derived2 x("X");
{
derived2 y("Y");
}
derived2 z("Z");
}

-------------compiler complaint------------------------------------
>main.obj : error LNK2019: unresolved external symbol "public: __thiscall derived2::~derived2(void)" (??1derived2@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public:
__thiscall derived2::derived2(char *)" (??0derived2@@QAE@PAD@Z)
referenced in function _main

what 's wrong with it?
Sep 3 '08 #1
4 1248
SamuelXiao <fo***********@gmail.comwrote:
-----------------------Lab002.h------------------------------
#ifndef _LAB_002_
#define _LAB_002_

class base{
char *msg;
public:
base(char *);
~base();
void print(void);
};

class derived1 : base{
public:
derived1(char *);
~derived1();
};

class derived2 : derived1{
public:
derived2(char *);
~derived2();
};
#endif

----------------------------main.cpp------------------------------
#include <iostream>
#include "Lab002.h"
using namespace std;

void main(void){
derived2 x("X");
{
derived2 y("Y");
}
derived2 z("Z");
}

-------------compiler complaint------------------------------------
main.obj : error LNK2019: unresolved external symbol "public: __thiscall
derived2::~derived2(void)" (??1derived2@@QAE@XZ) referenced in function
_main
1>main.obj : error LNK2019: unresolved external symbol "public:
__thiscall derived2::derived2(char *)" (??0derived2@@QAE@PAD@Z)
referenced in function _main

what 's wrong with it?
There are two things wrong with the above code.
1) 'main' returns an int, not void.

2) 'main' attempts to create several derived2 objects by using the
derived2::derived2(char*) constructor, unfortunately according to the
linker, no such constructor has been provided.

If you provided the constructor in a separate file, the consult your
compiler documentation on how to add the file to the link process.
Sep 4 '08 #2
Daniel T. wrote:
SamuelXiao <fo***********@gmail.comwrote:
>-----------------------Lab002.h------------------------------
#ifndef _LAB_002_
#define _LAB_002_

class base{
char *msg;
public:
base(char *);
~base();
void print(void);
};

class derived1 : base{
public:
derived1(char *);
~derived1();
};

class derived2 : derived1{
public:
derived2(char *);
~derived2();
};
#endif

----------------------------main.cpp------------------------------
#include <iostream>
#include "Lab002.h"
using namespace std;

void main(void){
derived2 x("X");
{
derived2 y("Y");
}
derived2 z("Z");
}

-------------compiler complaint------------------------------------
>>main.obj : error LNK2019: unresolved external symbol "public: __thiscall
derived2::~derived2(void)" (??1derived2@@QAE@XZ) referenced in function
_main
1>main.obj : error LNK2019: unresolved external symbol "public:
__thiscall derived2::derived2(char *)" (??0derived2@@QAE@PAD@Z)
referenced in function _main

what 's wrong with it?

There are two things wrong with the above code.
1) 'main' returns an int, not void.

2) 'main' attempts to create several derived2 objects by using the
derived2::derived2(char*) constructor, unfortunately according to the
linker, no such constructor has been provided.
[MONTY-PYTHON]
There are THREE things wrong with the above code.
[/MONTY-PYTHON]

3) The identifier for the include guard _LAB_002_ is reserved to the
implementation. You may not use it for your own purposes like that.
[MONTY-PYTHON]
There are THREE AND A HALF things wrong with the above code.
[/MONTY-PYTHON]

3.5) the (void) argument list is a C-ism, discouraged in C++. Avoid
its use.

As a side note, the contents of <iostreamare not used, and the
"using namespace std;" is unnecessary, since no members of std:: are
used.
Sep 4 '08 #3
I think the original question was about the specific error, not the
style.
I believe the author should take a closer look at "declaration vs.
definition" and "compilation and linkage" chapter of his course.

The simple solution would be to implement all declaration from
Lab002.h in main.cpp This is a bad practice, don't do that in the
future, but it is OK to start learning that way.
Sep 4 '08 #4
On 4 Sep, 04:27, red floyd <no.spam.h...@example.comwrote:
Daniel T. wrote:
SamuelXiao <foolsmart2...@gmail.comwrote:
-----------------------Lab002.h------------------------------
#ifndef _LAB_002_
#define _LAB_002_
class base{
* * * *char *msg;
public:
* * * *base(char *);
* * * *~base();
* * * *void print(void);
};
class derived1 : base{
public:
* * * *derived1(char *);
* * * *~derived1();
};
class derived2 : derived1{
public:
* * * *derived2(char *);
* * * *~derived2();
};
#endif
----------------------------main.cpp------------------------------
#include <iostream>
#include "Lab002.h"
using namespace std;
void main(void){
* * * *derived2 x("X");
* * * *{
* * * * * * * *derived2 y("Y");
* * * *}
* * * *derived2 z("Z");
}
-------------compiler complaint------------------------------------
main.obj : error LNK2019: unresolved external symbol "public: __thiscall
derived2::~derived2(void)" (??1derived2@@QAE@XZ) referenced in function
_main
1>main.obj : error LNK2019: unresolved external symbol "public:
__thiscall derived2::derived2(char *)" (??0derived2@@QAE@PAD@Z)
referenced in function _main
what 's wrong with it?
There are two things wrong with the above code.
1) 'main' returns an int, not void.
2) 'main' attempts to create several derived2 objects by using the
derived2::derived2(char*) constructor, unfortunately according to the
linker, no such constructor has been provided.

[MONTY-PYTHON]
There are THREE things wrong with the above code.
[/MONTY-PYTHON]

3) The identifier for the include guard _LAB_002_ is reserved to the
implementation. *You may not use it for your own purposes like that.

[MONTY-PYTHON]
There are THREE AND A HALF things wrong with the above code.
[/MONTY-PYTHON]

3.5) the (void) argument list is a C-ism, discouraged in C++. *Avoid
* * * its use.

As a side note, the contents of <iostreamare not used, and the
"using namespace std;" is unnecessary, since no members of std:: are
used.
Aren't there FOUR AND A HALF things wrong with the code?

To the OP: the errors you have shown each say "unresolved external
symbol". This means that the linker is dealing with a name, and it
wants to do something with the thing of that name, but it can't find
anything of that name (it can't "resolve" the name). The error
messages also give the name that it can't resolve.

The second is "derived2::derived2(char *)" - the constructor for
derived2 which takes a char * as its parameter. You said you were
going to provide such a constructor, and you've used it three times in
main, but, as Daniel said, you haven't actually provided it. Not in
the code you've posted, at least.

And the first is "derived2::~derived2(void)" - the destructor for
derived2. You said that you were going to provide one of these as
well, and so the computer will run it when it destroys the three
derived2s that you created - but again, you don't seem to have
actually provided it. It's not in the code you've posted, and if it's
in some other code, it doesn't seem to be getting linked properly.

Hope that helps.
Paul.

Sep 4 '08 #5

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

Similar topics

3
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- ...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
1
by: timVerizon | last post by:
Hoping someone can help here.. Our application (C#.Net) was receiving IBM.Data.DB2.DB2Exceptions ERROR SQL0904N Unsuccessful execution caused by an unavailable resource. Reason code: '', type...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
7
by: Martin Pritchard | last post by:
Hi, Sorry for my ignorance, but I'm a bit new to C++. I've been handed over a C++ app written in VS2002 which I have to convert to VS2005. Apparently it's been written in a C style, but cannot...
6
by: mahesh | last post by:
Hi friend, I am in deep trouble, I need to change the string in following format " 1.55576+2" in the floating point notation. that is i should have 155.576 as my output. Please suggest some...
1
by: Jedufa | last post by:
following of thread: "Adding namespaces to code behind automatically" Hello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I...
1
by: parasuit | last post by:
HI every body I need following programs for java .........please urgent i m biggner so help me................but urgent Problem # 1 An integer is said to be prime if it is...
1
by: patilanjana | last post by:
Hi, I am getting above mentioned errors. Checked msdn, read the comments but I fail to implement it. Please help. Error is regarding using the new and delete operators. Although I do write...
12
by: apicard | last post by:
I have a simple document like this: <Accept> <XXXX/> <Token image="From"/> <Date value="2007-01-01"/> <Token image="To"/> <Date value="2007-01-01"/> </Accept>
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.