4 Replies - 1147 Views - Last Post: 21 February 2010 - 11:52 PM Rate Topic: -----

#1 ohs14  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 13-October 09

I got a error message(ISO C++ forbids declaration)

Posted 21 February 2010 - 01:12 AM

This program is designed to do 2-d vector addition, subtraction,
dotproduct, and complex number addition, subtraction, multiplication.
I put //////////// which means error
#include<iostream>
using namespace std;
class GenVec
{
public:
 tdvector(float x1=0,float y1=0,float x2=0,float y2=0); /////// error(ISO C++ forbids declaration of ?dvector?with no typ)
 void vectoradd();
 void vectorSubtrct();
 void print();
 virtual void VecMultiply()=0;
public:
 float v1[2];
 float v2[2];
 float add[2];
 float sub[2];
 float mult[2];
};
class Complex: public GenVec
{
public:
  Complex(float x1=0,float y1=0,float x2=0,float y2=0);
  void VecMultiply();
  void print();
};
class TdVector: public GenVec
{
public:
 void VecMultiply();
};
int main()
{
 float x1,y1,x2,y2;
 cout << "Enter the first two numbers:" << endl;
 cin >> x1 >> y1;
 cout << "Enter the next two numbers:" << endl;
 cin >> x2 >> y2;
 cout << endl;
 Complex c1;
 TdVector t1;
 c1.vectoradd();
 c1.vectorSubtrct();
 c1.VecMultiply();
 c1.print();
 t1.vectoradd();
 t1.vectorSubtrct();
 t1.VecMultiply();
 t1.print();
}
GenVec::tdvector(float x1,float y1,float x2,float y2) /////////// same error
{
  for(int i=0; i<2; i++)
  {
  v1[0]=x1;
  v1[1]=y2;
  v2[0]=x2;
  v2[1]=y2;
  }
}
Complex::Complex(float x1,float y1,float x2,float y2):tdvector(x1,y2,x1,y2) ////////// error (class ?omplex?does not have any field named ?dvect)
{
}
void GenVec::vectoradd()
{
  for (int i=0; i<2; i++)
    add[i]=v1[i]+v2[i];
}
void GenVec::vectorSubtrct()
{
 for (int i = 0; i < 2; i++)
 sub[i] = v1[i] - v2[i];
}
void GenVec::print()
{
  cout << "Two vectors result" << endl;
  cout << "Addition: <" << add[0] << "," << add[1] << ">" << endl;
  cout << "Subtraction: " << sub[0] << "," << sub[1] << ">" << endl;
  cout << "Dot product: " << mult[0] << endl;
  cout << endl;
}
void Complex::VecMultiply()
{
  mult[0] = ((v1[0] * v2[0]) + (v1[1] * v2[1]));
}
void Complex::print()
{
  cout << "Two complex number results" << endl;
  cout << "Addition: " << add[0] << " + " << add[1] << "i" << endl;
  cout << "Subtraction: " << sub[0] << " + " << sub[1] << "i" << endl;
  cout << "Multiplication: " << mult[0] << " + " << mult[1] << "i" << endl;
}



Can you guys please fix it? Thank you
and I am wondering if my program works well after fixing the errors.

Is This A Good Question/Topic? 0
  • +

Replies To: I got a error message(ISO C++ forbids declaration)

#2 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: I got a error message(ISO C++ forbids declaration)

Posted 21 February 2010 - 09:19 PM

I am not sure what tdvector is supposed to be, but if it is a function, you need to specify a return type. For example:
void tdvector(float x1=0,float y1=0,float x2=0,float y2=0);


Was This Post Helpful? 0
  • +
  • -

#3 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 545
  • View blog
  • Posts: 1,420
  • Joined: 22-August 09

Re: I got a error message(ISO C++ forbids declaration)

Posted 21 February 2010 - 09:43 PM

There are actually a few problems here.

Firstly, I think you meant to have tdvector in your GenVec class as being the constructor. So that should be

 GenVec(float x1=0,float y1=0,float x2=0,float y2=0);



That being the case then

GenVec::tdvector(float x1,float y1,float x2,float y2) /////////// same error 



also needs to be changed to

GenVec::GenVec(float x1,float y1,float x2,float y2) /////////// same error 
{ 
  for(int i=0; i<2; i++) 
  { 
  v1[0]=x1; 
  v1[1]=y2; 
  v2[0]=x2; 
  v2[1]=y2; 
  } 
} 



Then, on the complex constructor, you will have this:

Complex::Complex(float x1,float y1,float x2,float y2):GenVec(x1,y2,x1,y2)dvect) 



That will clear the compilation errors, but you stll need to supply code for the TdVector::VecMultiply routine defined in the class below:

class TdVector: public GenVec 
{ 
public: 
 void VecMultiply(); 
}; 



Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#4 ohs14  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 13-October 09

Re: I got a error message(ISO C++ forbids declaration)

Posted 21 February 2010 - 11:47 PM

Thank both of you so much for helping me.
But,Martyn.Rae,

I don't really understand that
"you stll need to supply code for the TdVector::VecMultiply routine defined in the class below:"
class TdVector: public GenVec 
{ 
public: 
 void VecMultiply(); 
}; 



How should I fix this?
Was This Post Helpful? 0
  • +
  • -

#5 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: I got a error message(ISO C++ forbids declaration)

Posted 21 February 2010 - 11:52 PM

You need to define the function VecMultiply().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1