Home c++ Undefined Reference

Undefined Reference [Duplicate]

Author

Date

Category

Good “evening.” I ask for help with a linker error. There are two interrelated class (Enemy & amp; Container).

enemy.h

# pragma once
...
#Include "Container.h"
Class ENEMY {
Public:
  ...
  Void Effect (STD :: Shared_PTR & LT; EFFECT & GT;);
  ...
Private:
  ...
  Container & LT; STD :: Shared_PTR & LT; Effect & GT; & GT; Effects;
  ...
};

Container.h

# pragma once
...
class enemy;
TEMPLATE & LT; Class T & GT;
Class Container {
Public:
  void add_with_action (t, enemy & amp;);
};

ENEMY.CPP

...
Void Enemy :: Effect (STD :: Shared_PTR & LT; EFFECT & GT; EFFECT) {
  effects.add_with_action (EFFECT, * THIS);
}
...

container.cpp

# include "container.h"
TEMPLATE & LT; Class T & GT;
Void Container & LT; T & GT; :: Add_With_action (T EFFECT, ENEMY & AMP; EN) {
  ...
}
TEMPLATE & LT; Class T & GT;
Void Container & LT; T & GT; :: EXPIRED (T EFFECT) {
  ...
}

During Make, an error appears:

Game / Enemy.o: In Function
Enemy :: Effect (STD :: Shared_PTR & LT; Effect & GT;) ':
Enemy.cpp :(. Text + 0x952): undefined reference to
CONTAINER & LT; STD :: Shared_PTR & LT; Effect & GT; :: EXPIRED (STD :: Shared_PTR & LT; Effect & GT;) '
Enemy.cpp :(. Text + 0x98F): undefined reference to
Container & LT; STD :: Shared_PTR & LT; Effect & GT; :: Add_With_action (STD :: Shared_PTR & LT; Effect & GT;
Enemy & amp;) ‘Collect2: Error: LD Returned
1 EXIT STATUS

If I understand correctly, the problem is that classes depend on each other.


Answer 1, Authority 100%

Actually, it would be nice to implement the TEMPLATE-class methods Container transfer to Header. See https://ru.stackoverflow.com/questions/270465#270534

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions