Like Tree4Likes
  • 3 Post By whiteflags
  • 1 Post By sonjared

problem

This is a discussion on problem within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<conio.h> class test { private: float a,b,c; int q,w; public: int test(int q, int w=4) { return(q*w); } ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    23

    problem

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    
    class test
    {
    private:
    float a,b,c;
    int q,w;
    public:
    int test(int q, int w=4)
    {
    return(q*w);
    }
    float test(int a,int b,int c)
    {
    return ((a+b+c)/3);
    }
    };
    void main()
    {
    clrscr();
    test o,p,l;
    
    
    o=test(2,3);
    p=test(2);
    l=test(1,2,4);
    getch();
    }

    compiling error
    cant convert int to * test
    and also ::test

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,696
    I was able to fix most issues by writing main() this way.
    Code:
    #include <iostream>
    
    int main()
    {
      //clrscr();
      test o, p, l;
      float result;
    
    
      result = o.Test (2, 3);
      std::cout << "o.test(2, 3) result = " << result << std::endl;
      result = p.Test (2);
      std::cout << "p.test(2) result = " << result << std::endl;
      result = l.Test (1, 2, 4);
      std::cout << "l.test(1, 2, 4) result = " << result << std::endl;
      //getch();
    }
    On the errors I fixed: I started using iostream instead of iostream.h, because iostream.h is not a standard header and was the chief reason I could not compile your code. Then I replaced void main() with int main() as that is the standard definition. The only other thing I can say is: Do not write a method with the same name as the class. The compiler will treat such a function as a constructor, and return values are not allowed for constructors. I changed the name of the member functions accordingly just to get a build going.

    If you continue to have problems, please post complete errors.
    compiling error
    cant convert int to * test
    and also ::test
    This means NOTHING.
    vart, King Mir and antred like this.

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    It looks to me like a complete misunderstanding about classes and how they work. I would suggest re-reading the chapter about classes and constructors in your textbook with an eye toward correct syntax.
    whiteflags likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem passing argument into function, basic problem
    By tsdad in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2013, 12:09 PM
  2. Replies: 2
    Last Post: 01-06-2013, 06:49 AM
  3. Replies: 1
    Last Post: 12-07-2012, 09:00 AM
  4. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21