473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to remove the linker error in cpp programs with a class

hello..
Can anybody tell me how to remove the linker error as mentioned above..
i have created a simple program in C++ as given below
#include<iostream.h>
#include<conio.h>
void add(int a,int b);
void sub(int a,int b);
void mul(int a,int b);
void div(int a,int b);
class nikita
{
float c;
void add(int a,int b)
{
c=a+b;
cout<<"addition="<< c;
}
void sub(int a,int b)
{
c=a-b;
cout<<"substraction"<< c;
}
void mul(int a,int b)
{
c=a*b;
cout<<"multiplication"<< c;
}
void div(int a,int b)
{
c=a/b;
cout<<"div="<< c;
}
};
void main()
{
int a,b;
cout<<"enter the value of a";
cin>>a;
cout <<"enter the value of b";
cin>>b;
add(a,b);
sub(a,b);
mul(a,b);
div(a,b);
getch();
}
i saved it with name PIYUSHAN.cpp.after compiling above program, it shows no errors, that means it get compiled successfully. but when I try to run this program it shows Linker error : Undefined symbol add(int,int) in module PIYUSHAN.CPP
Linker error : Undefined symbol sub(int,int) in module PIYUSHAN.CPP
Linker error : Undefined symbol mul(int,int) in module PIYUSHAN.CPP
Linker error : Undefined symbol div(int,int) in module PIYUSHAN.CPP
Please help me out whats the problem and how to remove it....
Jun 3 '14 #1
6 2254
weaknessforcats
9,208 Expert Mod 8TB
You add the CPP file with the code for these missing functions to your build.

In your PIYUSHAN.CPP there is a call to a function
sub(int,int) using two integers. The compiler couldn't find the code for the function so it passed that job off to the linker who couldn't find the code either.
Jun 3 '14 #2
So what can i do now....
Jun 4 '14 #3
Can you please correct the code..
Jun 4 '14 #4
weaknessforcats
9,208 Expert Mod 8TB
I can't correct the code because the error is not in the code.

What compiler are you using? Is it one where you have to create a project and then build the project to get the executable? If so, you just add the cpp file(s) with the code for these undefined functions to the project and rebuild.
Jun 4 '14 #5
i am using turbo c++ IDE. can you please suggest me new compiler.
Jun 14 '14 #6
weaknessforcats
9,208 Expert Mod 8TB
How are you building your program?

Are you using a makefile or are you building a project that you have set up?
Jun 14 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Red Hammer | last post by:
Hi, I am new to using Visual C++ and trying to test it out. This is the simple program I wrote to test it: #define WIN32_LEAN_AND_MEAN #include <windows.h> // the main windows headers...
2
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been...
2
by: haplotype | last post by:
I have designed a package with several files, which is listed bellow base.cpp & base.hpp - define the template class base tree.cpp & tree.hpp - define the class tree derived from base<int>...
1
by: Laszlo | last post by:
Hi all, As a novice I installed PostgreSQL 7.2.1 on Win32 and works, Borland C++Builder Enterprise Suite 5.0 (build 12.34) what works too. I decided to combine these two programs and develop a...
9
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but...
6
by: nkrisraj | last post by:
Hi, I defined a simple method, getRecsize() inside one of the classes, Class RateRec as shown below. class RateRec { public: size_t getRecSize(void) const; ......
4
by: Mark | last post by:
Hi, I'm trying to write some classes that kind of manage themselves. A linked list, that links different types of objects. Here's the code... object.h: --- class Object { int alt;
1
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
7
by: simritsaini1982 | last post by:
hello.. Can anybody tell me how to remove the linker error as mentioned above.. i have created a simple program in C++ as given below #include<iostream.h> #include<conio.h> class ABC { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.