Member function not working

This is a discussion on Member function not working within the C++ Programming forums, part of the General Programming Boards category; Im kind of lost here; Mingw gives me a "Expected a constructor,destructor or type conversion before '.'token" main.cpp Code: #include ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Member function not working

    Im kind of lost here; Mingw gives me a "Expected a constructor,destructor or type conversion before '.'token"

    main.cpp
    Code:
    #include <iostream>
    #include "Stack.h"
    
    
    Stack s;
    
    s.Pop(); //The error
    
    int main()
    {
    	std::cout << "as"<< std::endl;
    	return 0;
    }
    Stack.h
    Code:
    #ifndef STACK_H
    #define STACK_H
    #include <iostream>
    using namespace std;
    
    
    
    class Stack
    {
        public:
            int GetSize();
            void Pop();
            void Push(int x);
            int Peek();
            Stack();
            virtual ~Stack();
    
        protected:
        private:
            int size;
    
            int data[];
    
    };
    #endif // STACK_H

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What do you expect your code to do? You are calling a member function that doesn't give a result, and you are doing this OUTSIDE any function in the code.

    --
    Mats

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    17
    It seems I forgot to post "Stack.cpp", sorry about that.
    Really, all I wanted for the code to do, was for it to compile. That is all.
    But thanks for the help.

    The argyle

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, even then, you need to place your code in such a place where the compiler accepts it, in this case, you may want to move s.pop() to inside main().

    --
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,252
    You can't have statements which are outside of any function. s.Pop() at global scope is illegal and meaningless. What exactly do you think it will do, anyway?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Calling a member function from a member function?
    By Chroder in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2002, 11:19 AM

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