CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2013
    Posts
    12

    Error returning object from function

    Code:
    class Main{
    	class B b_obj;
    	C c_obj=b_obj.test("some",89); // I cannot get this done.!
    
    }
    Below are .h files:
    
    class B{
    	public:
    	
    	C* test(const char *, int); /// this doesn't work
    	constructor
    	
    	//member variables
    }
    
    class C{
    	public:
    	constructor
    	
    	private:
    	map<string, vector<bol>> name;
    
    }
    C* test(const char *, int); /// this doesn't work
    C& test(const char *, int); /// this doesn't work
    name* test(const char *, int); //cannot work as name is private

    However,
    map<string, vector<bol>> test(const char *, int); works.
    I know second thing will work, but how to take reference of class object?

    I have include .h file in main, B and C, wherever it is required.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Error returning object from function

    Define "doesn't work".

  3. #3
    Join Date
    Oct 2013
    Posts
    12

    Re: Error returning object from function

    I get compile time errors.
    Quote Originally Posted by GCDEF View Post
    Define "doesn't work".

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Error returning object from function

    It would be more useful if you posted the actual full code rather than just pseudo code that says things like 'constructor'.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Error returning object from function

    Quote Originally Posted by deathmetal View Post
    I get compile time errors.
    Jeeze, is it too much trouble to actually post the errors. Ms. Cleo doesn't post here any more.

    Looking at what you posted, you're using a C before it's been defined. Without real code and real errors, it's just a guess.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured