class member function problem

This is a discussion on class member function problem within the C++ Programming forums, part of the General Programming Boards category; I am working on a class member function and am getting a couple of error messages that I don't understand. ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    class member function problem

    I am working on a class member function and am getting a couple of error messages that I don't understand.

    I am getting the following error messages:
    error 1 I think is because I'm performing a sqrt function which must be a double and putting it in an integer variable - converting to 'int' from 'double'

    error2: non -1 value in assignment

    The code below is supposed to run the blank function on vector p and find which location the blank spot is in. If the blank spot is in an "acceptable" position then the operation is performed. For example, if I had a vector of size 16 (user chooses side length and a vector of side length squared is created), I am filling the vector with the numbers from 1 through 15 and then leaving a "blank". for the example below, if the blank isn't located in the bottom row (vector is displayed as 4 rows and 4 columns) then the blank is swapped with the contents of the vector address directly above it.

    Please help me.

    Code:
    bool Puzzle::slide_up(const Puzzle& p) const {
      int location=blank(p);
      int d=Puzzle::p.size();
      int rows=sqrt(d);
     
      if(location<d-rows){
       int temp;
       temp=location;
       location=location+rows;
       location+rows=temp;
     return true;
      }
      else
      return false;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I doubt your error message says "non -1 value in assignment". I might believe l-value, given that it is surely impossible to assign anything to "location+rows" as you try to do.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    >>location+rows=temp;
    Is illegal in C++.
    The assignment must be on left and the value you assign on the right.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    ok. thank you. i was able to fix that problem with the help i received.

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    But there must be another problem:
    Code:
    int d=Puzzle::p.size();
    Do you mean a member function of a static variable in the class 'Puzzle', or a member function of the object 'p', i.e.,
    Code:
    int d=p.size();
    Very probably you mean the second option since you pass 'p' as argument...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

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