Problem about c++ new operator


 
Thread Tools Search this Thread
Top Forums Programming Problem about c++ new operator
# 1  
Old 04-24-2005
Problem about c++ new operator

#include <iostream.h>

class test
{
private:
int i;
public:
inline test(int m)
{
i = m;
}
inline int get_i()
{
return i;
}
};

int main()
{
test * a = new test(2);
cout << a->get_i();

return 0;
}

I compiled it in linux or solaris, there are always errors like:

In file included from /usr/local/include/c++/3.2/backward/iostream.h:31,
from test.cpp:1:
/usr/local/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
Undefined first referenced
symbol in file
operator new(unsigned) /var/tmp//cc3t8EU3.o
std::basic_ostream<char, std::char_traits<char> >:Smilieperator<<(int)/var/tmp//cc3t8EU3.o
operator delete(void*) /var/tmp//cc3t8EU3.o
std::cout /var/tmp//cc3t8EU3.o
std::ios_base::Init::~Init [in-charge]()/var/tmp//cc3t8EU3.o
std::ios_base::Init::Init[in-charge]()/var/tmp//cc3t8EU3.o
__gxx_personality_v0 /var/tmp//cc3t8EU3.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status




I seems that new operator can not be found. But even if changed the
#include <iostream.h>
with
#include <new>
#include <iostream>
using namespace std;

it does not work either.

Is there anybody who can give me some information to solve the problem ?

Thanks
# 2  
Old 04-24-2005
here is the error information using the linux gcc compilor.


In file included from /usr/include/c++/3.3.3/backward/iostream.h:31,
from test.cpp:4:
/usr/include/c++/3.3.3/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider usin
g one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples
include substituting the <X> header for the <X.h> header for C++ includes, or <s
stream> instead of the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
/cygdrive/c/DOCUME~1/Owner/LOCALS~1/Temp/ccLpbKDg.o(.text+0x27):test.cpp: undefi
ned reference to `operator new(unsigned)'
/cygdrive/c/DOCUME~1/Owner/LOCALS~1/Temp/ccLpbKDg.o(.text+0x52):test.cpp: undefi
ned reference to `std::cout'
/cygdrive/c/DOCUME~1/Owner/LOCALS~1/Temp/ccLpbKDg.o(.text+0x57):test.cpp: undefi
ned reference to `std::basic_ostream<char, std::char_traits<char> >:Smilieperator<<(
int)'
/cygdrive/c/DOCUME~1/Owner/LOCALS~1/Temp/ccLpbKDg.o(.text+0x83):test.cpp: undefi
ned reference to `std::ios_base::Init::Init[in-charge]()'
/cygdrive/c/DOCUME~1/Owner/LOCALS~1/Temp/ccLpbKDg.o(.text+0x9e):test.cpp: undefi
ned reference to `std::ios_base::Init::~Init [in-charge]()'
collect2: ld returned 1 exit status
# 3  
Old 04-26-2005
This is working fine with me :

--------------------------------------
*****************************
#include <iostream>
using namespace std;

class test
{
private:
int i;
public:
inline test(int m)
{
i = m;
}
inline int get_i()
{
return i;
}
};

int main()
{
test * a = new test(2);
cout << a->get_i();
return 0;
}

*****************************
--------------------------------------

I compiled the code using g++ compiler on solaris.

Also there is no need to specify methods as inline, if you are defining the method inside class declaration. By default it becomes inline.
# 4  
Old 04-27-2005
gcc, g++

use g++ instead of gcc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Help - Comparison Operator problem

Hi, I've tried searching through the forum but I've drawn a blank so i'm going to post here. I'm developing a number of checks on a CSV file, trying to find if any are greater than a max limit. I'm testing it by running it from a command line. The file I'm testing has 8 records. When I... (3 Replies)
Discussion started by: Tmart
3 Replies

2. Programming

Problem with STL's std::set container parameter to the operator << ()

Hi, I have this following code which gives me error when compiling. The problem is happening at the point where I create a const_iterator inside the overloaded insertion operator (i.e) operator << () function. The template argument version of set is not correct I guess. Could anyone please pitch... (3 Replies)
Discussion started by: royalibrahim
3 Replies

3. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

4. UNIX for Dummies Questions & Answers

Magic numbers '&' operator problem

Hello everyone, on the man page of "magic(5)" There is explanation "&, to specify that the value from the file must have set all of the bits that are set in the specified value" . My question is that what is the difference between '&' and equal operator '=' ? I tested it with file... (6 Replies)
Discussion started by: segmentation
6 Replies

5. UNIX for Dummies Questions & Answers

"binary operator exected" problem

Hey guys/gals, Am having trouble getting an 'if statement' to play nice.. I am playing with a script and need 'if' to check whether "y" or "Y" has been entered and if not to exit. In previous scripts I was playing with there would normally be a Y and a N response possibility so each... (2 Replies)
Discussion started by: TAPE
2 Replies

6. UNIX for Dummies Questions & Answers

+= operator

im new to bash scripting and im just using online tutorials and trial and error. i wanted to write a script to read numbers from a file and find their sum: #!/bin/bash theSum=0 for line in $(cat numbers.txt) do let "theSum = theSum + $line" echo "$line" done echo "The sum is... (3 Replies)
Discussion started by: astrolux444
3 Replies

7. UNIX for Dummies Questions & Answers

problem with pipe operator

hi i am having issues with extra pipe. i have a data file and i need to remove the extra pipe in the(example 4th and 7thline) in datafile. there are many other line and filed like this which i need to remove from files. The sample data is below: 270 31|455004|24/03/2010|0001235|72 271... (3 Replies)
Discussion started by: abhi_n123
3 Replies

8. UNIX for Dummies Questions & Answers

Problem unary operator expected

I get the following error ./get_NE05: line 42: while do echo ${STRING_NAME} J=1 if ; then EXT=0$I else EXT=$I fi while do echo $I-$J #calculating last occurrence OCCURRENCE=`grep -io "${STRING_NAME}"... (3 Replies)
Discussion started by: f_o_555
3 Replies

9. Shell Programming and Scripting

Problem with here doc operator in FTP script

Hello folks, I am facing a problem with the following korn shell script snippet: ftp -n -i -v <<EOF print -p open $CURR_HOST print -p user $USER $PASSWD print -p binary print -p cd /mydir/subdir/datadir print -p get $FILENAME print -p bye EOF exit It gives me the following... (3 Replies)
Discussion started by: Rajat
3 Replies

10. Shell Programming and Scripting

And operator

I am trying to check two variables and if both are blank I want to set a flag: the_f3_pid=`rsh $target ps -ef | grep "f3.eab" | awk '{print $2}'` the_f7_pid=`rsh $target ps -ef | grep "f7.eab" | awk '{print $2}'` if ; then y=1 fi I get an error: ./script_name: test: 0403-021 ]... (4 Replies)
Discussion started by: rcarnesiii
4 Replies
Login or Register to Ask a Question