C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-05-2008, 11:03 AM   #1
Registered User
 
Join Date: Nov 2008
Posts: 9
problem with classes

Hello!
I've got a problem with my classes - especially with private functions (I changed both private: into public:) and some kind of mistake in classes causes the fact that I cannot compile main function. What should I do?

Code:
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

//------------------------------------------------------------------------------

class point
{
   public:
      double x1, x2;
      double length()
      {
         return sqrt(pow(x1,2)+pow(x2,2)); //sqrt(x1^2+x2^2)
      }
      
      //I write that overloaded operator is a friend of this class.
      friend ostream & operator<<(ostream & theStream, point & thePoint);
};

//overloading operators point*double, double*point, point+point, point-point

point operator*(point x, double a)
{
   point result;
   result.x1 = x.x1 * a;
   result.x2 = x.x2 * a;
   return result;
}

point operator*(double a, point x)
{
   point result;
   result.x1 = x.x1 * a;
   result.x2 = x.x2 * a;
   return result;
}

point operator+(point & thePoint1, point & thePoint2)
{
   point sum;
   sum.x1 = thePoint1.x1 + thePoint2.x1;
   sum.x2 = thePoint1.x2 + thePoint2.x2;
   return sum;
}

point operator-(point & thePoint1, point & thePoint2)
{
   point sum;
   sum.x1 = thePoint1.x1 - thePoint2.x1;
   sum.x2 = thePoint1.x2 - thePoint2.x2;
   return sum;
}

//overloaded operator <<
ostream & operator<<(ostream & theStream, point & thePoint)
{
   theStream<<"["<<thePoint.x1<<", "<<thePoint.x2<<"]";
   return theStream;
}

//------------------------------------------------------------------------------

class hessian
{
   public: //I've got a problem with determinant (in main function there is
           //a problem with compiling if I use 'private' here!!!!!!!!
      double x00, x01, x10, x11;
      //|x00 x01|
      //|x10 x11|
      double determinant;
   public:
      friend point operator*(hessian theHessian, point thePoint);
      friend hessian operator*(hessian theHes1, hessian theHes2);
      void det();
      void invertHessian();
      void hessianAtPoint(point thePoint);
      friend ostream&operator<<(ostream & theStream, hessian & theHessian);
};

//internal functions - determinant, invert hessian and hessian at point

void hessian::det()
{ determinant = x00 * x11 - x10 * x01; }

void hessian::invertHessian()
{
   //inverted matrix: A^(-1) = A^D / det(A)
   //A = [(a, b), (c, d)], A^D = [(d, -b), (-c, a)]
   double _x00, _x01, _x10, _x11;
   _x00 =  x11/determinant;
   _x01 = -x01/determinant;
   _x10 =  x10/determinant;
   _x11 =  x00/determinant;
   x00 = _x00; x01 = _x01; x10 = _x10; x11 = _x11;
}

void hessian::hessianAtPoint(point thePoint)
{
   x00 = x11 = 2;
   x01 = x10 = 0;
}

//overloading operators << and hessian*hessian

ostream&operator<<(ostream & theStream, hessian & theHessian)
{
   theStream<<"|"<<theHessian.x00<<" "<<theHessian.x01<<"|]n";
   theStream<<"|"<<theHessian.x10<<" "<<theHessian.x11<<"|]n";
}

hessian operator*(hessian theHes1, hessian theHes2)
{
   hessian result;
   //simple multiplication matrix by matrix
   //[a b][e f] = [ae+bg af+bh]
   //[c d][g h]   [ce+dg cf+dh]
   result.x00 = theHes1.x00 * theHes2.x00 + theHes1.x01 * theHes2.x10;
   result.x01 = theHes1.x00 * theHes2.x01 + theHes1.x01 * theHes2.x11;
   result.x10 = theHes1.x10 * theHes2.x00 + theHes1.x11 * theHes2.x10;
   result.x11 = theHes1.x10 * theHes2.x01 + theHes1.x11 * theHes2.x11;
}

//------------------------------------------------------------------------------

class gradient
{
   public: //???????????????????
      point myPoint;
   public:
      void gradientAtPoint(point thePoint);
      friend ostream&operator<<(ostream & theStream, gradient & theGradient);
};

void gradient::gradientAtPoint(point thePoint)
{
   myPoint.x1 = 2 * thePoint.x1 - 1;
   myPoint.x2 = 2 * thePoint.x2 - 1;
}

ostream&operator<<(ostream & theStream, gradient & theGradient)
{
   theStream<<theGradient.myPoint;
   return theStream;
}

//------------------------------------------------------------------------------

//overloading other operator: hessian*point

point operator*(hessian theHessian, point thePoint)
{
   point result;
   //[x00 x01] * [x1 x2] = [x00*x1 + x01*x2]
   //[x10 x11]             [x10*x1 + x11*x2]
   result.x1 = theHessian.x00 * thePoint.x1 + theHessian.x01 * thePoint.x2;
   result.x2 = theHessian.x10 * thePoint.x1 + theHessian.x11 * thePoint.x2;
}

//main function

double myFunction(point thePoint)
{ return (pow(thePoint.x1, 2)+pow(thePoint.x2, 2)); };

//------------------------------------------------------------------------------

int main(int argc, char *argv[])
{
   //declaring variables
   gradient myGradient;
   hessian  myHessian;
   point    myPoint;
   double   accuracy;
   int      n = 0;
   
   //stating input variables
   cout<<"Write the input value x1 = ";
   cin>>myPoint.x1;
   cout<<"Write the input value x2 = ";
   cin>>myPoint.x2;
   cout<<"Write the accuracy = ";
   cin>>accuracy;
   
   //main algorithm
   myGradient.gradientAtPoint(myPoint);
   while (myGradient.gradientAtPoint(myPoint) > accuracy)
   {
      n++;
      myGradient.gradientAtPoint(myPoint);
      myHessian.hessianAtPoint(myPoint);
      myHessian.det();
      myHessian.invertHessian();
      thePoint = thePoint - myHessian * myGradient.x;
   }
   
   //writing output
   cout<<"\n[x1, x2] = ["<<thePoint.x1<<", "<<thePoint.x2<<"]";
   cout<<"\nminimum value = "<<function(thePoint);
   cout<<"\naccuracy = "<<accuracy;
   cout<<"\nnumber of iterations = "<<n<<"\n";
   system("PAUSE");
   return EXIT_SUCCESS;
}

//And by the way - I've got other question. If I'd like the user to be able to
//change the function, is there any way to allow this application to read the
//fuction (and gradient, hessian) from the file and put inside those lines which
//are responsible for calculations?
Regards!
zdzislavv is offline   Reply With Quote
Old 12-05-2008, 11:25 AM   #2
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
Quote:
What should I do?
Post the compile errors and highlight the lines they refer to.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 12-05-2008, 12:05 PM   #3
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
Warning 1 warning C4100: 'thePoint' : unreferenced formal parameter g:\w00t\visual studio 2008\projects\temp\temp4.cpp 99
Error 2 error C2120: 'void' illegal with all types g:\w00t\visual studio 2008\projects\temp\temp4.cpp 187
myGradient.gradientAtPoint returns void, yet you try to compare if it is higher than something...

Error 3 error C2065: 'thePoint' : undeclared identifier g:\w00t\visual studio 2008\projects\temp\temp4.cpp 194
Error 4 error C2065: 'thePoint' : undeclared identifier g:\w00t\visual studio 2008\projects\temp\temp4.cpp 194
thePoint is not declared/defined anywhere!

Error 5 error C2039: 'x' : is not a member of 'gradient' g:\w00t\visual studio 2008\projects\temp\temp4.cpp 194
Self-explanatory.

Error 6 error C2065: 'thePoint' : undeclared identifier g:\w00t\visual studio 2008\projects\temp\temp4.cpp 198
Error 7 error C2228: left of '.x1' must have class/struct/union g:\w00t\visual studio 2008\projects\temp\temp4.cpp 198
Error 8 error C2065: 'thePoint' : undeclared identifier g:\w00t\visual studio 2008\projects\temp\temp4.cpp 198
Error 9 error C2228: left of '.x2' must have class/struct/union g:\w00t\visual studio 2008\projects\temp\temp4.cpp 198
Error 10 error C2065: 'thePoint' : undeclared identifier g:\w00t\visual studio 2008\projects\temp\temp4.cpp 199
thePoint is not defined, so it cannot have members!

Error 11 error C3861: 'function': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 199
What is function(thePoint) supposed to do?

This leaves me to believe you do not even have a compiler. Or at least you never compile when you write the code.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.

Last edited by Elysia; 12-05-2008 at 12:08 PM.
Elysia is offline   Reply With Quote
Old 12-05-2008, 02:06 PM   #4
Registered User
 
Join Date: Nov 2008
Posts: 9
I compile when writing a code. I use Dev-C++ (I know that's not the best idea), version 4.9.9.2.
I noticed some errors here, it is corrected version (and "point itsPoint;" in line 130.):
Code:
   //main algorithm
   myGradient.gradientAtPoint(myPoint);
   while (myGradient.itsPoint.length() > accuracy)
   {
      n++;
      myGradient.gradientAtPoint(myPoint);
      myHessian.hessianAtPoint(myPoint);
      myHessian.det();
      myHessian.invertHessian();
      myPoint = myPoint - (myHessian * (myGradient.itsPoint));
   }
   
   //writing output
   cout<<"\n[x1, x2] = ["<<myPoint.x1<<", "<<myPoint.x2<<"]";
   cout<<"\nminimum value = "<<myFunction(myPoint);
   cout<<"\naccuracy = "<<accuracy;
   cout<<"\nnumber of iterations = "<<n<<"\n";
I wrote in my first post that I've got a problem with private variables inside the classes (so I replaced it with public). The other thing is compiling error:
Quote:
E:\Dev-Cpp\oadm-o2\main.cpp In function `int main(int, char**)':
194 E:\Dev-Cpp\oadm-o2\main.cpp no match for 'operator-' in 'myPoint - operator*(myHessian, ((const point&)((const point*)((point*)(&myGradient)))))'
note E:\Dev-Cpp\oadm-o2\main.cpp:49 candidates are: point operator-(point&, point&)
E:\Dev-Cpp\oadm-o2\Makefile.win [Build Error] [main.o] Error 1
for the line:
Code:
      myPoint = myPoint - (myHessian * (myGradient.itsPoint));
Regards.
zdzislavv is offline   Reply With Quote
Old 12-05-2008, 02:17 PM   #5
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
myPoint (which, again, is never defined anywhere), is probably of type Point, but Point does not define an operator -, so any - operation on the object is illegal.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-05-2008, 02:20 PM   #6
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,845
I'm guessing that the compiler is balking at turning the temporary object returned by operator* into a reference to pass into operator-. Does making the parameters of operator- into const Point & help?
tabstop is offline   Reply With Quote
Old 12-05-2008, 02:24 PM   #7
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
But then again, perhaps you could help us out by posting your complete code that actually works? Your original code was as broken, it did not even get to the stage where you currently are, apparently.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-07-2008, 06:34 AM   #8
Registered User
 
Join Date: Nov 2008
Posts: 9
Actual code:

Code:
//Newton-Raphson Method
//http://en.wikipedia.org/wiki/Newton's_method

#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

//------------------------------------------------------------------------------

class point
{
   public:
      double x1, x2;
      double length()
      {
         return sqrt(pow(x1,2)+pow(x2,2)); //sqrt(x1^2+x2^2)
      }
      
      //I write that overloaded operator is a friend of this class.
      friend ostream & operator<<(ostream & theStream, point & thePoint);
};

//overloading operators point*double, double*point, point+point, point-point

point operator*(point x, double a)
{
   point result;
   result.x1 = x.x1 * a;
   result.x2 = x.x2 * a;
   return result;
}

point operator*(double a, point x)
{
   point result;
   result.x1 = x.x1 * a;
   result.x2 = x.x2 * a;
   return result;
}

point operator+(point & thePoint1, point & thePoint2)
{
   point sum;
   sum.x1 = thePoint1.x1 + thePoint2.x1;
   sum.x2 = thePoint1.x2 + thePoint2.x2;
   return sum;
}

point operator-(point & thePoint1, point & thePoint2)
{
   point sum;
   sum.x1 = thePoint1.x1 - thePoint2.x1;
   sum.x2 = thePoint1.x2 - thePoint2.x2;
   return sum;
}

//overloaded operator <<
ostream & operator<<(ostream & theStream, point & thePoint)
{
   theStream<<"["<<thePoint.x1<<", "<<thePoint.x2<<"]";
   return theStream;
}

//------------------------------------------------------------------------------

class hessian
{
   public: //I've got a problem with determinant (in main function there is
           //a problem with compiling if I use 'private' here!!!!!!!!
      double x00, x01, x10, x11;
      //|x00 x01|
      //|x10 x11|
      double determinant;
   public:
      friend point operator*(hessian theHessian, point thePoint);
      friend hessian operator*(hessian theHes1, hessian theHes2);
      void det();
      void invertHessian();
      void hessianAtPoint(point thePoint);
      friend ostream&operator<<(ostream & theStream, hessian & theHessian);
};

//internal functions - determinant, invert hessian and hessian at point

void hessian::det()
{ determinant = x00 * x11 - x10 * x01; }

void hessian::invertHessian()
{
   //inverted matrix: A^(-1) = A^D / det(A)
   //A = [(a, b), (c, d)], A^D = [(d, -b), (-c, a)]
   double _x00, _x01, _x10, _x11;
   _x00 =  x11/determinant;
   _x01 = -x01/determinant;
   _x10 =  x10/determinant;
   _x11 =  x00/determinant;
   x00 = _x00; x01 = _x01; x10 = _x10; x11 = _x11;
}

void hessian::hessianAtPoint(point thePoint)
{
   x00 = x11 = 2;
   x01 = x10 = 0;
}

//overloading operators << and hessian*hessian

ostream&operator<<(ostream & theStream, hessian & theHessian)
{
   theStream<<"|"<<theHessian.x00<<" "<<theHessian.x01<<"|]n";
   theStream<<"|"<<theHessian.x10<<" "<<theHessian.x11<<"|]n";
}

hessian operator*(hessian theHes1, hessian theHes2)
{
   hessian result;
   //simple multiplication matrix by matrix
   //[a b][e f] = [ae+bg af+bh]
   //[c d][g h]   [ce+dg cf+dh]
   result.x00 = theHes1.x00 * theHes2.x00 + theHes1.x01 * theHes2.x10;
   result.x01 = theHes1.x00 * theHes2.x01 + theHes1.x01 * theHes2.x11;
   result.x10 = theHes1.x10 * theHes2.x00 + theHes1.x11 * theHes2.x10;
   result.x11 = theHes1.x10 * theHes2.x01 + theHes1.x11 * theHes2.x11;
}

//------------------------------------------------------------------------------

class gradient
{
   public: //???????????????????
      point itsPoint;
   public:
      void gradientAtPoint(point thePoint);
      friend ostream&operator<<(ostream & theStream, gradient & theGradient);
};

void gradient::gradientAtPoint(point thePoint)
{
   itsPoint.x1 = 2 * thePoint.x1 - 1;
   itsPoint.x2 = 2 * thePoint.x2 - 1;
}

ostream&operator<<(ostream & theStream, gradient & theGradient)
{
   theStream<<theGradient.itsPoint;
   return theStream;
}

//------------------------------------------------------------------------------

//overloading other operator: hessian*point

point operator*(hessian theHessian, point thePoint)
{
   point result;
   //[x00 x01] * [x1 x2] = [x00*x1 + x01*x2]
   //[x10 x11]             [x10*x1 + x11*x2]
   result.x1 = theHessian.x00 * thePoint.x1 + theHessian.x01 * thePoint.x2;
   result.x2 = theHessian.x10 * thePoint.x1 + theHessian.x11 * thePoint.x2;
}

//main function

double myFunction(point thePoint)
{ return (pow(thePoint.x1, 2)+pow(thePoint.x2, 2)); };

//------------------------------------------------------------------------------

int main(int argc, char *argv[])
{
   //declaring variables
   gradient myGradient;
   hessian  myHessian;
   point    myPoint;
   point    tempPoint;
   double   accuracy;
   int      n = 0;
   
   //stating input variables
   cout<<"Write the input value x1 = ";
   cin>>myPoint.x1;
   cout<<"Write the input value x2 = ";
   cin>>myPoint.x2;
   cout<<"Write the accuracy = ";
   cin>>accuracy;
   
   //main algorithm
   myGradient.gradientAtPoint(myPoint);
   while (myGradient.itsPoint.length() > accuracy)
   {
      n++;
      myGradient.gradientAtPoint(myPoint);
      myHessian.hessianAtPoint(myPoint);
      myHessian.det();
      myHessian.invertHessian();
      //myPoint = myPoint - (myHessian * (myGradient.itsPoint)); //[1]
      tempPoint = myHessian * myGradient.itsPoint;               //[2]
      myPoint = myPoint - tempPoint;                             //[3]
      //Here I changed line [1] into lines [2] and [3].
      //I think both [1] and [2][3] are the same but [1] doesn't compile.
   }
   
   //writing output
   cout<<"\n[x1, x2] = ["<<myPoint.x1<<", "<<myPoint.x2<<"]";
   cout<<"\nminimum value = "<<myFunction(myPoint);
   cout<<"\naccuracy = "<<accuracy;
   cout<<"\nnumber of iterations = "<<n<<"\n";
   system("PAUSE");
   return EXIT_SUCCESS;
}

//And by the way - I've got other question. If I'd like the user to be able to
//change the function, is there any way to allow this application to read the
//fuction (and gradient, hessian) from the file and put inside those lines which
//are responsible for calculations?
This code compiles but still there may be some logical errors. I changed 198 into 199 and 200.

Code:
//myPoint = myPoint - (myHessian * (myGradient.itsPoint)); //[1]
tempPoint = myHessian * myGradient.itsPoint;               //[2]
myPoint = myPoint - tempPoint;                             //[3]
//Here I changed line [1] into lines [2] and [3].
//I think both [1] and [2][3] are the same but [1] doesn't compile.
myPoint is declared in line 176.

point has got operator-
point operator-(point & thePoint1, point & thePoint2) //line 51
zdzislavv is offline   Reply With Quote
Old 12-07-2008, 06:42 AM   #9
The larch
 
Join Date: May 2006
Posts: 3,222
Warnings with MingW

Quote:

Untitled1.cpp:103: warning: unused parameter 'thePoint'

Untitled1.cpp: In function `std::ostream& operator<<(std::ostream&, hessian&)':

Untitled1.cpp:114: warning: control reaches end of non-void function
Untitled1.cpp: In function `hessian operator*(hessian, hessian)':
Untitled1.cpp:126: warning: control reaches end of non-void function

Untitled1.cpp: In function `point operator*(hessian, point)':
Untitled1.cpp:162: warning: control reaches end of non-void function

Untitled1.cpp: At global scope:

Untitled1.cpp:172: warning: unused parameter 'argc'
Untitled1.cpp:172: warning: unused parameter 'argv'

Execution terminated
Compilation successful
Go to Compiler Setting (or Project Settings) and add -Wall to "additional compiler commands". Not returning anything is a pretty bad error.
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 12-07-2008, 06:46 AM   #10
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Code:
point operator-(point & thePoint1, point & thePoint2)
You need to make the parameters to operator-() const, so that the compiler can allow a temporary variable to be passed as a reference (or not use references, but that's a worse option).


Code:
         return sqrt(pow(x1,2)+pow(x2,2)); //sqrt(x1^2+x2^2)
can I suggest that you use:
Code:
         return sqrt(x1 * x1 + x2 * x2);
It's much faster and at least as readable.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 12-07-2008, 09:10 AM   #11
Registered User
 
Join Date: Nov 2008
Posts: 9
1. Untitled1.cpp:103: warning: unused parameter 'thePoint'
In the class point there is declaration of x1 and x2:
Code:
class point
{
   public:
      double x1, x2;
In the line no. 103 I take 'point thePoint', so it should contain those x1 and x2. I'm operating on x00, x01, x10, x11, which are variables of class hessian.
Code:
void hessian::hessianAtPoint(point thePoint)
{
   x00 = x11 = 2;
   x01 = x10 = 0;
}
In the line 195 I've got
Code:
myHessian.hessianAtPoint(myPoint);
In my code program operates on very easy function. But if I used more complicated function than function from line 167, I would write different formulas in lines 104 and 105. Those different formulas would be functions which use variables x0 and x1 taken from myPoint. This is why I don't use myPoint.
Question: does it properly change variables x00, x11, x01, x10 from myHessian into 2, 2, 0 and 0?

2. I don't understand this:
Quote:
Untitled1.cpp: In function `std:stream& operator<<(std:stream&, hessian&)':

Untitled1.cpp:114: warning: control reaches end of non-void function
I take reference to stream and hessian and then write values of variables in the console. So what is wrong?

3. Similar problem with
Quote:
Untitled1.cpp: In function `hessian operator*(hessian, hessian)':
Untitled1.cpp:126: warning: control reaches end of non-void function
I added return result;
Code:
result.x11 = theHes1.x10 * theHes2.x01 + theHes1.x11 * theHes2.x11;
return result;
I guess now it should work properly.
zdzislavv is offline   Reply With Quote
Old 12-07-2008, 10:54 AM   #12
The larch
 
Join Date: May 2006
Posts: 3,222
"control reaches end of non-void function" means that you don't return anything (in all execution paths). operator<< should return the same ostream that you take as an argument, so that chaining like cout << a << b would work.

The unused parameter for hessianAtPoint means that you don't use the argument at all. Why should a point be passed if it is not going to be used for anything? (This may be desirable, though, but then you just don't have to give a name to the argument:

Code:
void hessian::hessianAtPoint(point);
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 12-07-2008, 11:45 AM   #13
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
Quote:
Originally Posted by anon View Post
Warnings with MingW
What in the blazes?
Not returning something from a function that is supposed to return something is an error, not a warning.

Visual Studio gives me:
Warning 1 warning C4100: 'thePoint' : unreferenced formal parameter g:\w00t\visual studio 2008\projects\temp\temp2.cpp 102
Warning 2 warning C4100: 'argv' : unreferenced formal parameter g:\w00t\visual studio 2008\projects\temp\temp2.cpp 171
Warning 3 warning C4100: 'argc' : unreferenced formal parameter g:\w00t\visual studio 2008\projects\temp\temp2.cpp 171
Error 4 error C4716: 'operator<<' : must return a value g:\w00t\visual studio 2008\projects\temp\temp2.cpp 114
Error 5 error C4716: 'operator*' : must return a value g:\w00t\visual studio 2008\projects\temp\temp2.cpp 126
Error 6 error C4716: 'operator*' : must return a value g:\w00t\visual studio 2008\projects\temp\temp2.cpp 162
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-07-2008, 01:10 PM   #14
The larch
 
Join Date: May 2006
Posts: 3,222
That's really up to the standard to decide. It seems that VC++ is improvising a bit here: it does produce warning C4715 in less clear cases (e.g not a return in every branch). Not that it isn't useful, but you can use -Werror with MinGW too.
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 12-07-2008, 01:11 PM   #15
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
So they have NOT decided if it an error or not?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with classes and pointers Akkernight C++ Programming 18 02-21-2009 06:21 AM
Memory problem with Borland C 3.1 AZ1699 C Programming 16 11-16-2007 11:22 AM
Having a problem with Classes FoxTrot C++ Programming 10 09-06-2007 07:40 PM
Problem with destructors. Hulag C++ Programming 7 06-11-2004 12:30 PM
problem w/ nested templatized classes *ClownPimp* C++ Programming 8 10-19-2002 07:58 AM


All times are GMT -6. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22