Getting a:"member is not of class type" error

This is a discussion on Getting a:"member is not of class type" error within the C++ Programming forums, part of the General Programming Boards category; I am doing a simple test and when I try to call the member from the class that I created ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Getting a:"member is not of class type" error

    I am doing a simple test and when I try to call the member from the class that I created it says that the member isn't of the class type specified. I have called it for the class but I'm still getting the error.

    Code:
    #ifndef INFIX_CONVERTER_H
    #define	INFIX_CONVERTER_H
    
    #include <stack>
    #include <map>
    #include <string>
    
    /*
    Precondition for this converter must be that all input is correct
    infix input must consist of digits 0-9 and operators +, -, *, /.
    */
    class InfixConverter
    {
    	std::map<char, int> prec;	//the precendence values of operators
    	
    	public:
    		InfixConverter();
    		~InfixConverter() {} 
    		std::string toPost(std::string&);
    };
    
    
    #endif
    test
    Code:
    #include <iostream>
    #include "Stack.h"
    #include "InfixConverter.h"
    
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    
    int main(int argc, char *argv[])
    {
    	InfixConverter postServe();
    	cout << postServe.toPost("2+3+4*5^4") << endl;
    	return 0;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >std::string toPost(std::string&);
    Code:
    std::string toPost(const std::string&);
    My best code is written with the delete key.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,465
    std::string toPost(const std::string&)
    If you aren't changing the argument.

    If you are, you need to pass it a string object and not a string literal.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    still got the error.

    Also, I've gotten that same error for different situations, how do I interpret that error in different cases?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >so the compiler assumes that the string being returned is the string being
    >passed to it if not explicitly stating one's const to indicate that it's seperate?
    That's a fascinating conclusion, but no. You simply can't tell the compiler that the string is writable and then pass a read-only argument.
    My best code is written with the delete key.

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    ahh, I realized that so I changed it, and it's wrong still The code not you
    Last edited by indigo0086; 11-20-2006 at 09:11 AM.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,465
    What change have you made?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    My first change was the const. My second was changing the parameter from a literal to a string object. Still get the same error.
    main.cpp:13: error: request for member `toPost' in `postServe', which is of non-class type `InfixConverter ()()'
    Process terminated with status 1 (0 minutes, 0 seconds)

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >InfixConverter postServe();
    Lose the parens. The compiler thinks you're declaring a function.
    My best code is written with the delete key.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,465
    Ah! That's different.

    check your object declaration. It probably is InfixConverter postServe();.

    You will be declaring a function called postServe which takes no arguments and returns an InfixConverter object. That's not what you want.

    You don't need (and you shouldn't) use () to create an object with the default constructor
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Ahhh, that's the same error I got in another thing I was doing and did the change. I forgot. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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