Linking error

S

Sunil Varma

Hi,

I'm facing linking error when I try to build this code.
If I just compile, it compiles properly.

#include <iostream>

using namespace std;

class vc1
{
public:
virtual void vf()=0;
};

class vc2
{
public:
virtual void vf()=0;
};

class concrete:public vc1, public vc2
{
public:
virtual void vc1::vf()
{
cout<<"vc1::vf()\n";
}
virtual void vc2::vf()
{
cout<<"vc2::vf()\n";
}
};

void main()
{
concrete *obj = new concrete;
obj->vc1::vf();
obj->vc2::vf();
}

These are the errors observed

main.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall vc2::vf(void)" (?vf@vc2@@UAEXXZ) referenced in
function _main
main.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall vc1::vf(void)" (?vf@vc1@@UAEXXZ) referenced in
function _main

I'm using VC 8 compiler.

Thanks in advance.

Sunil
 
S

ssylee

Hi,

I'm facing linking error when I try to build this code.
If I just compile, it compiles properly.

#include <iostream>

using namespace std;

class vc1
{
public:
        virtual void vf()=0;

};

class vc2
{
public:
        virtual void vf()=0;

};

class concrete:public vc1, public vc2
{
public:
        virtual void vc1::vf()
        {
                cout<<"vc1::vf()\n";
        }
        virtual void vc2::vf()
        {
                cout<<"vc2::vf()\n";
        }

};

void main()
{
        concrete *obj = new concrete;
        obj->vc1::vf();
        obj->vc2::vf();

}

These are the errors observed

main.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall vc2::vf(void)" (?vf@vc2@@UAEXXZ) referenced in
function _main
main.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall vc1::vf(void)" (?vf@vc1@@UAEXXZ) referenced in
function _main

I'm using VC 8 compiler.

Thanks in advance.

Sunil

This may be unrelated to the answer of this question, but you may want
to change your main function as such:

int main(int argc, char *argv[])
{
concrete *obj = new concrete;
obj->vc1::vf();
obj->vc2::vf();

delete obj;
return 0;
}
 
D

Default User

ssylee wrote:

This may be unrelated to the answer of this question, but you may want
to change your main function as such:

int main(int argc, char *argv[])
{
concrete *obj = new concrete;
obj->vc1::vf();
obj->vc2::vf();

delete obj;
return 0;
}


Those parameters aren't used, so why declare them?




Brian
 
D

Daniel T.

I'm facing linking error when I try to build this code.
If I just compile, it compiles properly.

Your code should not compile. See below:
#include <iostream>

using namespace std;

class vc1
{
public:
        virtual void vf()=0;

};

class vc2
{
public:
        virtual void vf()=0;

};

class concrete:public vc1, public vc2
{
public:

error: qualified name is not allowed
        virtual void vc1::vf() ^
        {
                cout<<"vc1::vf()\n";
        }

error: qualified name is not allowed
        virtual void vc2::vf() ^
        {
                cout<<"vc2::vf()\n";
        }

};

void main()
{

error: object of abstract class type "concrete" is not allowed:
        concrete *obj = new concrete;
^
 
S

Sunil Varma

Could you let me know the compiler you are using?
I'm trying to build it in Visual Studio 2005, there if I just compile,
it compiles without errors.
But when I build, I observe linking errors.

Thanks
Sunil
 
D

Daniel T.

Could you let me know the compiler you are using?
I'm trying to build it in Visual Studio 2005, there if I just
compile, it compiles without errors. But when I build, I observe
linking errors.

http://www.comeaucomputing.com/tryitout/

Aparently Visual Studio 2005 is getting it wrong. I also compiled it
in my head based on my knowledge of the language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top