"Storage class specified" for C++ code

Jun 30, 2011 at 11:56am
Hi all

I am running an image processing algorithm using OpenCV library and C++ in Eclipse SDE. here is my code...the unnecessary stuff is removed..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <stdio.h>
#include "evalulation_criteria.h"

using namespace std;

int main( int argc, char** argv )
{

        evaluation_criteria e_criteria
        ofstream save_inv;
	save_inv.open("saved_data_invariant.txt");

        while(.....) {       //OpenCV structures follow
        
        //call to member function of class e_criteria

        }
        save_inv.close();
}

//class header

#ifndef EVALUTATION_CRITERIA_H_
#define EVALUTATION_CRITERIA_H_


#include "opencv/cxcore.h"
#include "opencv/cv.h"
#include <fstream>

using namespace std;

class evalutation_criteria {

private:

extern ofstream save_inv;
// other member data

public:

//member data


};

#endif  /* EVALUTATION_CRITERIA_H_ */


//class implementation 


#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cxcore.h"

#include "evalutation_criteria.h"

using namespace std;

// void constructor and destructor

void evalutation_criteria::calc(....){

        save_inv<<(float) value;  

}


I get only the "storage class specified for save_inv" error. I have checked the program many times for any missing semicolons but it compiles fine if i remove the extern keyboard (which is clearly not the purpose)....How do I pass the ofstream objects between main and class member functions to write to the same txt file then?

Thanks for all your help








Last edited on Jun 30, 2011 at 11:58am
Jun 30, 2011 at 1:34pm
do you want to use a typedef?
Jun 30, 2011 at 2:04pm
I dont mind using typedef but i do not know how it will solve my problem..i am a newbie to c++ so kindly bear with me.
Jun 30, 2011 at 2:17pm
This extern ofstream save_inv; doesn't work. You cannot make a local variable extern. Pass ofstream &save_inv to evalutation_criteria::calc()
Jun 30, 2011 at 2:28pm
thanks coder777 for that serious error. i cant send the
ofstream &save_inv
to the function as it hampers my requirements. I tried creating save_inv as a global object but the error still lingers. I know global variables are not a good programming practice, but since I am developing an algorithm solely it should be fine I guess.
Jun 30, 2011 at 3:07pm
thanks coder777 I have solved it with what you said. I passed the address! I am a big fan of pointers now :D
Topic archived. No new replies allowed.