yun
yun

Reputation: 1283

Inheritance - Symbol undefined Objective-C++

quick question... this is just a misunderstanding on inheritance my end so this should be quick to fix (I'm using objective-c++). I'll take the question off if it's already been solved... I couldn't find it hence my post:

I have the following:

Base.h file

#ifndef BASE_H
#define BASE_H

class Base {
public:
    // Virtual Constructor
    Base() {}; 
}
#endif

Derived.h file

// Derived.h
#ifndef DERIVED_H
#define DERIVED_H

#include "Base.h"

class Derived : public Base {
public:
    Derived();
}
#endif

Derived.cpp file

// Derived.cpp
#include "Derived.h"

Derived::Derived() {
    // Do construction here!
}

Wrapper.mm file

// Wrapper.mm
#include "Derived.h"

- (id)init {
    if (self = [super init]) {
        Base *b = new Derived();     // Cannot compile?
    }
}

I'm getting a undefined error for "Derived::Derived()" referenced from -[Wrapper init] in Wrapper.o; Symbol(s) not found for architecture arm64. How do I fix this? Thanks!

Upvotes: 1

Views: 93

Answers (1)

xaxxon
xaxxon

Reputation: 19751

You're not linking the .o file generated when compiling Derived.cpp. Just add Derived.o to the end of your compiler arguments when you compile your Wrapper.mm file to create an executable and you should be good (though I hadn't even ever heard of obj-c++ before)

Upvotes: 2

Related Questions