Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Error when using EXIT_FAILURE C++ in eclipse
Error when using EXIT_FAILURE C++ in eclipse [message #1777643] Fri, 01 December 2017 08:56 Go to next message
J M is currently offline J MFriend
Messages: 7
Registered: November 2017
Junior Member
Hello everyone,

I wrote a simple code that does the substraction of two vectors, and when I want to return "EXIT_FAILURE" in an "if condition", I have an error saying "could not convert '1' from int to std::vector<double>" (see joint image: error_exit_failure.png). In my code I included "cstdlib.h" where EXIT_FAILURE is defined, here's my code:

std::vector<double> substract_two_vectors(std::vector<double> const &vect1,std::vector<double> const &vect2)
{
	//the second vector is substracted from the first one
	int size_vect1 = vect1.size();
	int size_vect2 = vect2.size();

	if(size_vect1!=size_vect2)
	{
		printf("Error, The vectors to substract should have the size size \n");
		return EXIT_FAILURE;
	}

	//declare the vector to be filled and returned afterwards
	std::vector<double> result(size_vect1);
	for(int i=0;i<size_vect1;i++)
	{
		result[i]=vect1[i]-vect2[i];
	}

	return result;
}

Re: Error when using EXIT_FAILURE C++ in eclipse [message #1777654 is a reply to message #1777643] Fri, 01 December 2017 09:38 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 357
Registered: August 2014
Senior Member
This is actually off-topic for Eclipse, just a C++ question.

Your function says to return a vector, but the EXIT_FAILURE is an enumeration integer intended to be returned from main().

The compiler tells that you cannot return a bunch of bananas from a single apple you're offering.


--

Tauno Voipio
Re: Error when using EXIT_FAILURE C++ in eclipse [message #1777664 is a reply to message #1777654] Fri, 01 December 2017 10:47 Go to previous messageGo to next message
J M is currently offline J MFriend
Messages: 7
Registered: November 2017
Junior Member
Thanks for your answer.
Actually I understood what the error meant, but given the fact that I have the exact same code developed in C in another IDE, I thought that it might be an Eclipse issue.

[Updated on: Fri, 01 December 2017 10:48]

Report message to a moderator

Re: Error when using EXIT_FAILURE C++ in eclipse [message #1777705 is a reply to message #1777664] Fri, 01 December 2017 19:37 Go to previous message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 357
Registered: August 2014
Senior Member
You cannot compile the C++ code in C, so it was not *exact* the same code. Your problem was in converting an integer scalar to a vector (which exists as such in C++ only).

What was the return type of the function in C?


--

Tauno Voipio
Previous Topic:Project "... g++" not found in PATH
Next Topic:Where did the "use parallel build" checkbox go?
Goto Forum:
  


Current Time: Fri Dec 15 12:13:23 GMT 2017

Powered by FUDForum. Page generated in 0.02076 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software