Solved

error on compilng a C++ file using g++

Posted on 2008-06-12
4
382 Views
Last Modified: 2012-05-05
Hi group,

I'm getting warning as following when I compile two cpp files. These are not my files it happened I found them at http://www.functionx.com/cpp/examples/simpleclass.htm as I was trying to learn how "ctags" works in VIM or vi

In order to compile and run I use:

$g++ Exo.cpp Cube.cpp   -o  test

Questions:
1) What caueses warning and how can I fix it? currently I have output which works fine but need to know how to get rid of this warnnig.
2)Does anybody know how I can use ctags in vim? any good resource with example?




Source is at snippet window but error message is:

In file included from /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/backward/iostream.h:31,
                 from cube.cpp:2:
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.



Header File: cube.h  
 
 
#ifndef CUBE_H
#define CUBE_H
 
class Cube
{
public:
	Cube();
	~Cube();
	void setSide(double s);
	double getSide();
	double Area();
	double Volume();
	void Properties();
private:
	double Side;
};
 
#endif
Source File cube.cpp  
 
 
#include <iostream.h>
#include "cube.h"
 
Cube::Cube()
{
}
 
Cube::~Cube()
{
}
 
void Cube::setSide(double s)
{
	Side = s <= 0 ? 1 : s;
}
 
double Cube::getSide()
{
	return Side;
}
 
double Cube::Area()
{
	return 6 * Side * Side;
}
 
double Cube::Volume()
{
	return Side * Side * Side;
}
 
void Cube::Properties()
{
	cout << "Characteristics of this cube";
	cout << "\nSide   = " << getSide();
	cout << "\nArea   = " << Area();
	cout << "\nVolume = " << Volume() << "\n\n";
}
Main File: Exo.cpp  
 
 
#include "cube.h"
 
void main()
{
	Cube cube;
	cube.setSide(-12.55);
	cube.Properties();
 
	Cube de;
	de.setSide(28.15);
	de.Properties();
}

Open in new window

0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 21766836
The warning is telling you that you are using deprecated features of C++. In this case, if you look at line 25 you'll see you include <iostream.h> rather than <iostream>. The former header is deprecated by the C++ Standard. THis was done when namespaces were introduce into the langauge. The code in iostream.h isn't in a namespace, whereas the code in iostream will be in the std:: namespace. You should prefer to use the correct header in you code and use a using namespace std; clause if necessary. Try chaning this and the warning should go, I couldnt' see any other obvious sign of deprecated use in your cade.

I don't know about vim ctags... sorry.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21766866
BTW: If you can't or don't want to change the code (I'd advise you do) then, as the warning states, you can use the -Wno-deprecated g++ option to remove the warning.

g++ -Wno-deprecated Exo.cpp Cube.cpp -o  test

Additional...

All the old C++ headers that ended in .h were renamed to exclude the .h and the old ones were deprecated. All the C style headers were also renamed to start with a C also with the .h removed. For example, c++ header <string.h> is now called <string> and C header <stdlib.h> is now called <cstdlib>. You should use these new headers in preference to the old ones when writing C++ (When writing C you should prefer to use the original C headers, for example <stdlib.h>). Again, this is to do with placing things int he std:: namespace. It's a little bit of a mess but once you learn the rules it's not that big a deal.

0
 

Author Comment

by:akohan
ID: 21766904

Hi Evilrix,

Thank so much  for your advice. Now, I understand what it means.

About ctags I found it. It is a way of finding the declarations or definitions of enums, functions and classes and so. In big projects it is very helpful.

http://linux.byexamples.com/archives/177/vim-with-ctags/


Regards.


0
 
LVL 40

Expert Comment

by:evilrix
ID: 21767048
>> Thank so much  
Very welcome and thanks for posting back about CTags.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question