Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6033959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:33:33+00:00 2026-05-23T05:33:33+00:00

Say I have this physical structure: / +– conflicttest | +– A.cpp | +–

  • 0

Say I have this physical structure:

/
  +-- conflicttest
  |     +-- A.cpp
  |     +-- A.h
  |     +-- main.cpp
  +-- libconflict
  |     +-- conflict
  |     |     +-- A.h
  |     |     +-- B.h
  |     +-- A.cpp
  |     +-- B.cpp

These are the sources of libconflict, take a deep breath:

class B header in libconflict:

// libconflict B.h
class B
{
public:
    void bar();
protected:
    int j_;
};

class B implementation in libconflict:

// libconflict B.cpp
#include "conflict/B.h"

void B::bar()
{
    std::cout << "B::bar" << std::endl;
}

class A header in libconflict:

// libconflict A.h
# include "conflict/B.h"

class A : public B
{
public:
    A();
private:
    int i_;
};

class A implementation in libconflict:

#include "conflict/A.h"

A::A()
{
    std::cout << "libconflict A is alive" << std::endl;
    i_ = 51; // some random fields and values... I should admit I am lost
    j_ = 47;
}

Now the sources of conflicttest, it’s almost over:

class A header in conflicttest:

// conflicttest A.h
class A
{
public:
    A();
    void foo();
};

class A implementation in conflicttest:

// conflicttest A.cpp
#include "A.h"

A::A()
{
    std::cout << "A is alive" << std::endl;
}

void A::foo()
{
    std::cout << "A::foo" << std::endl;
}

and finally, main.cpp:

// main.cpp in conflicttest
#include "conflict/A.h"

int main()
{
    B* b = new A;
    b->bar();
return 0;
}

Phew… I am using Visual Studio 2010 to build this solution. conflicttest is an executable which is linked against the static library libconflict.
This compiles like a charm, but, believe it or not, the output is :

A is alive
B::bar

The linker actually uses the symbol A from conflicttest which is absolutely not a B and worse, it can invoke B::bar().

I am lost, how come the compiler doesn’t complain?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:33:34+00:00Added an answer on May 23, 2026 at 5:33 am

    You have violated the One Definition Rule.

    The compiler didn’t complain because it is limited in the things it can detect when crossing translation unit boundaries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
Say i have this PHP code: $FooBar = a string; i then need a
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
say I have this $result = mysql_query('SELECT views FROM post ORDER BY views ASC');
Say I have this column returned in a command for Crystal: deposit_no 123 130
Say I have this table: Person table -------------- PersonId Address table ------------ AddressId PersonAddressId
Say I have this table schema. ID AccNo Amount Say I have this data
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.