0

A.h file

class A{
      public:
      static int* func (int &b);
}

A.cpp

int* A::func(int &b){
   //some definition here
}

I am calling the above function in some other file. I have included the .h file in that. When I try to compile I get the following error

undefined reference to A::func(int &)

9
  • Are you supplying the compiled object code of A.cpp (let's call it A.obj) to your linker? Commented Sep 13, 2012 at 4:33
  • @Als Yes, I have linked the cpp file. Commented Sep 13, 2012 at 4:34
  • 1
    Post the command you use to compile this file. Commented Sep 13, 2012 at 4:35
  • I think first you should get a compiler error of making A::func() as private! The link error could be due to not linking A.o file. Commented Sep 13, 2012 at 4:38
  • Do you perchance wrap the file in namespace Something { ... }? Commented Sep 13, 2012 at 4:41

1 Answer 1

1

The code looks right.

The first thing to check is that your build environment compiled and linked in A.cpp.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.