Jump to content

c++ undefined reference error

DiamondShark286

I am fairly new o c++ but I have done plenty of java before. I have two method in the same .cpp file but when I try to call one from the other it gives me an undefined reference error but I have called other methods from this file also and it works fine. please help!

Link to comment
Share on other sites

Link to post
Share on other sites

did you define the method before calling the method?

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

Please give us the complete error message, preferably including the code around the line where the error occurs. My first assumption would be that you're not using a header file and you try to call a method which is not known at the point.

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, djdwosk97 said:

did you define the method before calling the method?

it was defined in a separate header file just as all the other methods were

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Tb428 said:

it was defined in a separate header file just as all the other methods were

Post the code then. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Dat Guy said:

Please give us the complete error message, preferably including the code around the line where the error occurs. My first assumption would be that you're not using a header file and you try to call a method which is not known at the point.

sorry don't currently have my computer with me but here is what it looked like:

cpp file:

void method1(double x, double y, double z){
	//code here
}

void method2(){
	x1 = 5;
	y1 = 6.3;
	z1 = 7;
	method1(x1, y1, z1);
}

hpp file:

namespace HEAD {
	class Body{
      	public:
      		double x1;
      		double y1;
      		double z1;
      
    		void method1(double x, double y, double z);
      		void method2();
      	
    }
}

and yes the header file is included 

Link to comment
Share on other sites

Link to post
Share on other sites

Body::method1(...)?

 

Other than that, we still could need the precise error message.

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Dat Guy said:

Body::method1(...)?

 

Other than that, we still could need the precise error message.

tried that the error message was:

undefined reference to "HEAD::Body::method1(double, double, double)"

 

Link to comment
Share on other sites

Link to post
Share on other sites

Digured it out i forgot the namespace nd class declaration before it in the cpp file. Sorry guys not to expierieced with c++.

Link to comment
Share on other sites

Link to post
Share on other sites

Digured it out i forgot the namespace nd class declaration before it in the cpp file. Sorry guys not to expierieced with c++.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×