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

Threaded View

  1. #1
    Join Date
    Apr 2010
    Posts
    26

    What is wrong in this program?

    What i am trying to do here is to pass an argument from int main() to num2 then using the same value pass the argument to num1 but the compiler is acting like the arguments passed to num1 does not belong to the class' private member. What's the problem and what is the problem's name? I want to find it in the net or textbook.

    Code:
    #include<iostream>
    #include <string>
    
    using namespace std;
    class num1
    {
    int a;
    int b;
    
    public:
    
    num1(int h,int g):a(h),b(g){};
    
    int addnum()
    {
    return a+b;
    }
    
    };
    
    class num2
    {
    num1 c( int x, int y);
    
    public:
    
    num2 (int a, int b)
    {
    x=a;
    y=b;
    
    }
    
    int funct()
    {return c.addnum();}
    };
    
    int main()
    {
    num2 f(1,2);
    cout<<f.funct();
    return 0;
    }
    Last edited by hayloiuy; July 23rd, 2010 at 11:53 PM. Reason: Not specific

Tags for this Thread

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