Compiling a multpile file project.

Gregness (2)
Hey everyone, I'm using Dev-C++ to write a barebones image processor for my Data structures class and I'm having trouble combining all of my files.

From Driver.cpp

1
2
3
4
5
6
7
#include <iostream>
#include <fstream>
#include <cmath>
#include "image.h"
#include "image.cpp"

using namespace std;


image.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef IMAGE_H
#define IMAGE_H


using namespace std;

// a simple example - you would need to add more funtions

class ImageType {
 public:
   // functions irrelevant to the problem
   void negateImage(/*stub*/);
   ImageType& operator+(&ImageType);/*stub*/
   ImageType& operator-(&ImageType);/*stub*/
   ImageType& operator=(&ImageType);/*stub*/


image.cpp

1
2
3
4
5
//#include <stdlib.h>
//#include <stdio.h>
#include "image.h"

using namespace std;



Some of the #includes are commented out because I thought perhaps I had done something wrong, but nothing I tried seemed to help.

These is the compiler error I'm getting:

ISO C++ forbids declaration of `ImageType' with no type
expected `;' before '&' token

I get that one for all three of the overloaded operators.

So, how exactly to I manage all the #includes so that Dev-C++ will be able to compile my files correctly? Or is there something else going on?
Disch (7378)
when making references, the & comes after the typename. Just like your return type.

Also, your + and - operators probably shouldn't be returning a reference.

And you should also probably make this const correct while you're at it:

1
2
3
4
5
6
7
class ImageType {
 public:
   // functions irrelevant to the problem
   void negateImage(/*stub*/);
   ImageType operator+(const ImageType&) const; // const correct, doesn't return a reference
   ImageType operator-(const ImageType&) const; // ditto
   ImageType& operator=(const ImageType&); // this should return a reference 
Gregness (2)
That was a rookie mistake on my part, but I'm still getting the "ISO C++ forbids declaration of `ImageType' with no type" error. Is there something wrong with the class specification?
Disch (7378)
what line is giving you that error?
demosthenes2k8 (174)
Are you making sure to finish the class with a };?
Topic archived. No new replies allowed.