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

Page 1 of 1

## 4 Replies - 1215 Views - Last Post: 21 February 2010 - 11:52 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=157319&amp;s=373123724e56c577cca3b9199d6f0060&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ohs14

Reputation: 2
• 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 vectorSubtrct();
void print();
virtual void VecMultiply()=0;
public:
float v1[2];
float v2[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.vectorSubtrct();
c1.VecMultiply();
c1.print();
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)
{
}
{
for (int i=0; i<2; 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 << "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 << "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-

• D.I.C Regular

Reputation: 61
• 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);

```

### #3 Martyn.Rae

• The programming dinosaur

Reputation: 547
• 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.

### #4 ohs14

Reputation: 2
• 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?

### #5 PlasticineGuy

• mov dword[esp+eax],0

Reputation: 281
• 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().