Click here to Skip to main content
14,773,751 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to using enum passing the parameter to virtual function. I want to practice the Strategy mode of design pattern. Here is my code(example) ,which should print "Hello".(C++), I ran but error, Error message:
undefined reference to `test(Enum)'

What I have tried:

I don't know how to fix the code.

Here is my code:

class Base
  virtual void show() = 0;

class child1 : public Base
  void show(){

enum Enum {

int main() {
    Base* test(Enum);
auto the_test =test(child1);
    return 0;
Updated 5-Dec-20 0:22am

1 solution

Just about everything is wrong with your code. You are trying to instantiate an abstract class. You are trying to create an instance by passing a class name to a parameterless constructor. You are using the same names for a class, and an enumeration value. I suggest you go back to the C++ documentation and study the section on classes again.
Rick York 5-Dec-20 13:48pm
A trifecta of errors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900