| | |
passing objects as arguments
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi
I am attempting to pass a reference to an object from one function to another, is this even possible, if so what is the syntax this is an example of what I want:
Obviously the functions and classes I am using are a lot more complicated the class itself in the program I am writing takes about 5 seconds to construct due to it dealing and containing a huge amount of data. I don't want to have to reinitialise this class everytime I use it I want to just be able to point a reference to it. Does anyone know how to do this?
I have tried the method above, also:
void foo(SomeClass &reference)
void foo(SomeClass *reference)
and about 10 other variations on this, the usual error message I get is:
no matching function for call to `keyword_cache::find_keyword(const char[6])'
Any help will be greatly appreciated.
Thanks
Ben
I am attempting to pass a reference to an object from one function to another, is this even possible, if so what is the syntax this is an example of what I want:
C++ Syntax (Toggle Plain Text)
class SomeClass { public: int a = 100; }; void second_function(SomeClass & ref_to_classobj) { std::cout << ref_to_classobj.a << endl; } int main() { SomeClass classobj; second_function(classobj); return 0; }
Obviously the functions and classes I am using are a lot more complicated the class itself in the program I am writing takes about 5 seconds to construct due to it dealing and containing a huge amount of data. I don't want to have to reinitialise this class everytime I use it I want to just be able to point a reference to it. Does anyone know how to do this?
I have tried the method above, also:
void foo(SomeClass &reference)
void foo(SomeClass *reference)
and about 10 other variations on this, the usual error message I get is:
no matching function for call to `keyword_cache::find_keyword(const char[6])'
Any help will be greatly appreciated.
Thanks
Ben
Application development, webhosting, and much more: www.webcentric-hosting.com
What you have written as an example looks correct. Your error message suggests a different issue at work? Perhaps the function find_keyword does not take a const string?
find_keyword( char* keyword )
if you said:
find_keyword( "123456" );
you would likely get the error you mention, because "123456" is a six char const array. (heck, maybe its 7 with a trailing null, but you get the idea)
find_keyword( char* keyword )
if you said:
find_keyword( "123456" );
you would likely get the error you mention, because "123456" is a six char const array. (heck, maybe its 7 with a trailing null, but you get the idea)
•
•
•
•
Originally Posted by Chainsaw
What you have written as an example looks correct. Your error message suggests a different issue at work? Perhaps the function find_keyword does not take a const string?
The actual call I was making was
C++ Syntax (Toggle Plain Text)
void test_class(keyword_cache &test) { test.find_keyword("black"); }
It was translating the "black" at a char array not a string.
Thanks for the help.
Ben
Application development, webhosting, and much more: www.webcentric-hosting.com
![]() |
Similar Threads
- Objects as arguments (Java)
- Passing Objects (C++)
- variable arguments in C (C)
- Problem with execv argument passing (C++)
Other Threads in the C++ Forum
- Previous Thread: have a try if you are interested in...
- Next Thread: how to make colors
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





