By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

cpp compiler error

P: 1
I am getting an error when compiling a cpp file which includes implementation of template.
ERROR IS:
/tmp/cc9YgzIB.o(.text+0x7a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/cc9YgzIB.o(.text+0xa9): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/cc9YgzIB.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Myfile is:
#include<iostream>
#include<stdio.h>
template<class T>
void swap(T &a,T &b)
{
T temp=a;
a=b;
b=temp;
}
int main()
{
int a,b;
char *c,*d;
printf("enter the values of a and b \n");
scanf("%d %d",&a,&b);
printf("enter the values of c and c \n");
scanf("%s %s",c,d);
swap(a,b);
swap(c,d);
printf("the values of a=%d ,b=%d " ,a,b);
printf("the values of c=%s ,d=%s ",c,d);
return 0;
}
Sep 29 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
A see only one error (and get only 1 error when I compile this code) which is that you write to the pointers c and d without actually pointing them anywhere

you need a

c = new char[100];
d = new char[100];


and

delete[] c;
delete[] d;

In your program
Sep 29 '06 #2

Post your reply

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