Wednesday 15 May 2013

c++ - Access predefined objects in header files -



c++ - Access predefined objects in header files -

i working external library provide class, library_class_1, , take inputs , homecoming outputs usual. want able access these outputs in header file, in order utilize info in class. having problem passing info separate header files. post thought of script big , contains lot of other non-relevant info question.

"main.cpp" #include header.h int main { ... library_class_1 object_1; header object_2; object_2.dosomething(...) // how input object_1 correctly? } "header.h" class header { public: header(); void dosomething( ); // how can pass object_1 in here? } "header.cpp" #include header.h header::header() {...} header::dosomething( ) // how can pass object_1 in here? { // here, want able access fellow member functions of // object_1 }

if declare

"header.h" header::dosomething(library_class_1 & object_1); "header.cpp" void dosomething(library_class_1 & object_1);

i error:library_class_1 has not been declared (in "header.h")

i believe have declare function somehow in "header.h", have not been able so. tried defining

class library_class_1; // or library_class_1 object_1;

in "header.h", without success.

anyways, please don't mind formatting/implementation errors wanted give thought of question. hope explained correctly question.

add forwards declaration of library_class_1 in header.h before using it.

class library_class_1; class header { public: header(); void dosomething(library_class_1 const& object_1); }

make sure #include .h file defines library_class_1 in header.cc.

#include <librarry_class_1.h> void header::dosomething(library_class_1 & object_1) { // utilize object_1 ... }

c++

No comments:

Post a Comment