little help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: little help

  1. #1
    Join Date
    Jan 2009
    Posts
    14

    little help

    How can i initialize a variable called get_info?
    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    struct Rectangle
    {
    	double width;
    	double length;
    };
    void get_info (Rectangle &abcd);
    {
    	cout<<"Enter the length: ";
    	cin>>abcd.length;
    	cout<<"Enter the width: ";
    	cin>>abcd.width;
    }
    int main()
    {
    	Rectangle get_info;
    		cout<<"The area of the rectangle is: "<< get_info.length*get_info.width;
    	return 0;
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,261

    Re: little help

    I suggest giving the Rectangle object a better name than get_info, especially since get_info is already a name of a function. If you really insist on the conflicting and rather misleading name, then you have to qualify the name of the function as being in the global namespace, e.g.,
    Code:
    Rectangle get_info;
    ::get_info(get_info);
    cout<<"The area of the rectangle is: "<< get_info.length*get_info.width;
    By the way, it looks like you have a stray semi-colon at the end of this line:
    Code:
    void get_info (Rectangle &abcd);
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    Re: little help

    Quote Originally Posted by igodspeed View Post
    How can i initialize a variable called get_info?
    Write a constructor for it.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center