Thread: Problem with CPP Classes, probably easy fix

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    58

    Problem with CPP Classes, probably easy fix

    This is my class...

    Code:
    class ivar
    {
    public:
    	float real, immaginary;
    	ivar(){};					// Constructor
    //	~ivar(){};
    	ivar(float, float);
    	ivar operator + (ivar);
    	ivar operator - (ivar);
    	ivar operator * (ivar);
    	ivar iscreen(float maxx, float minx, float maxi, float mini, int screenx, int screeny, int x, int y);
    	ivar iantiscreen(float maxx, float minx, float maxy, float miny, int screenx, int screeny, int sx, int sy);
    }z, c;
    and this is the iscreen function:

    Code:
    ivar ivar::iscreen(float maxx, float minx, float maxi, float mini, int screenx, int screeny, int x, int y)
    {
    	ivar answer;
    	answer.real=((maxx-minx)/screenx)*x+minx;
    	answer.immaginary=((maxi-mini)/screeny)*y+mini;
    	return(answer);
    }
    and when I try to use this function later on in the program with this:

    Code:
    c=ivar.iscreen(maxX, minX, maxY, minY, ScreenX, ScreenY, x, y);
    the compiler gives me the error:

    expected primary-expression before '.' token

    ------------------------------
    I don't know what I'm doing wrong, this is the first time I've used classes, and following the tutorials precisely leads me to this implementation, however it doesn't seem to work!

    Any Class enlightenment would be of great service. Thanks!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    c=ivar.iscreen(maxX, minX, maxY, minY, ScreenX, ScreenY, x, y);
    ivar is a type, not a variable. If you intend to use it to create an object of type ivar, you may want to use a static member function [1]. But in this case, why not just make iscreen work on "this", and then do c.iscreen(...)? That would be the traditional way to provide this type of functionality.

    [1] A static function is one that doesn't operate on a class object in itself - it just belongs to the class anyways.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    58
    You have no idea what you've done...

    You saved me:

    *12 cans of minute maid lemonade,
    *the time it takes to run back and forth to the bathroom 7 times
    *a major headache
    *a growing complex uninterest in class jargon
    *a very angry me

    I really appreciate your help! Rock ON WITH YOU!

    Also very quick response thank you for that too

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So which of the two solutions did you choose?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    58
    I chose to go with the way that classes are meant to be used, c.iscreen(...);

    Its so much easier and I get the concept of classes just a bit more. Thanks : )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange problem with dev cpp
    By henrychan22 in forum C++ Programming
    Replies: 8
    Last Post: 06-18-2006, 11:05 AM
  2. problem with classes
    By xxmetalheadxx in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 08:02 AM
  3. Easy weard C++ problem
    By Airwin in forum C++ Programming
    Replies: 4
    Last Post: 12-26-2005, 08:18 AM
  4. problem with c++ classes
    By student2005 in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2003, 05:58 PM
  5. Overflowing string... any easy way to fix it?
    By Trauts in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2002, 08:35 PM