a question about "quote"

This is a discussion on a question about "quote" within the C++ Programming forums, part of the General Programming Boards category; hi , while was programming , i confronted a problem. Code: #include<iostream.h> class sample { int x,y; public: sample(int a,int ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    China,Nanjing
    Posts
    15

    Angry a question about "quote"

    hi ,
    while was programming , i confronted a problem.
    Code:
    #include<iostream.h>
    class sample
    {
      int x,y;
    public:
      sample(int a,int b)
      {x=a;
        y=b;
      }
      int getx()
      {
        return x;
      }
      int gety()
      {
        return x+y;
      }
    };
    int main()
    {
      int (sample::*fp)();
      fp=sample::getx;
      sample s(2,5);
      int v =(s.*fp)();
      fp=sample::gety;
      int t=(s.*fp)();
      cout<<"v="<<v<<",t="<<t<<endl;
      return 0;
    }
    i can compile it under windows VC++,however i can not compile it under linux with g++
    can someone find the answer..
    thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    Post your error messages.
    VC++ 6 is an old compiler, and iostream.h is an obsolete header file.
    g++ (new ones) only accept <iostream>, and there are things called namespaces to deal with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    China,Nanjing
    Posts
    15

    Angry

    Quote Originally Posted by Salem View Post
    Post your error messages.
    VC++ 6 is an old compiler, and iostream.h is an obsolete header file.
    g++ (new ones) only accept <iostream>, and there are things called namespaces to deal with.
    i have changed <iostream.h> to <iostream>

    but it does not work as well...

    and when i use <iostream.h> to compile other programmes,all of which can been done..

    the follow code can not be passed while compiling...
    Code:
    int (sample::*fp)();
    Last edited by wxjeacen; 02-19-2009 at 10:51 PM.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Quote Originally Posted by Salem View Post
    Post your error messages.
    four characters

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    From a glance, these are errors:
    fp=sample::getx;
    fp=sample::gety;
    To take the address of a member function, you must use the address-of operator &.
    They should be:
    fp=&sample::getx;
    fp=&sample::gety;
    And upgrade your compiler if possible. These errors are many more were fixed in Visual Studio 2005.
    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.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    China,Nanjing
    Posts
    15
    Quote Originally Posted by Elysia View Post
    From a glance, these are errors:
    fp=sample::getx;
    fp=sample::gety;
    To take the address of a member function, you must use the address-of operator &.
    They should be:
    fp=&sample::getx;
    fp=&sample::gety;
    And upgrade your compiler if possible. These errors are many more were fixed in Visual Studio 2005.
    thank you very much!!!

    i recorrect the code ,and it works..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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