Thread: Newbie question, error "expected primary-expression before objectname"

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    12

    Newbie question, error "expected primary-expression before objectname"

    Hi,

    I am a complete newbie to C++, I come from Perl and used to know a little C++, but I very newbie. I am just trying to include a header file and its class (I get no errors from the include) and then create an object. Thats all that I'm doing at this point, except for some stuff that also worked without error, taking command line variables and printing them back out (that stuff I won't copy here, I promise you it works). The bug is either in my include and call to the constructor in the main file (hello_world.c) or its in the header file or the class file or something to with with how I include them. The bug from g++ is "expected primary-expression before publicagent" and "expected ";" before publicagent"

    My code goes like this:

    Code:
    #include <iostream>
    #include <cstdlib>
    #include "PublicFirm.h"
    
    // global variables and user input
    int input;
    ... // 5 more
    
    int main (int argc, char* argv[])
    {
    
      if( argc != 6 )
        {
        cout << "Usage ...\n";
        exit(0);
        }
    
    cout<< "hello\n";
    
     input = atoi(argv[1]);
     ... // 5 more
    
    cout<< "Okay, strarting...";
    
    PublicFirm publicagent;
    
    cout << "instantiated\n";
    
    return 0;
    
    }
    
    
    The header and class files look like this:
    
    header:
    
    #ifndef __PublicFirm__
    #define __PublicFirm__
    
    namespace PublicFirm
    {
    
    class PublicFirm
      {
    // trial
      private:
        int privatevalue; 
    
    // constructor
    // destructor
    // trial method
    
      public:
        PublicFirm(); 
        virtual ~PublicFirm(); 
        virtual int getValue(); 
    
      };
    
    
    }
    
    #endif
    
    
    the class file:
    
    #include "PublicFirm.h"
    #include <stdio.h>
    
    
    namespace PublicFirm
    {
    
      PublicFirm::PublicFirm()
      {
        //cout << "Constructing...";
        //privatevalue += 1;
    
      }
    
      PublicFirm::~PublicFirm()
      {
        //cout << "Destructing...";
    
      }
    
      int PublicFirm::getValue(int i)
      {
        //cout << privatevalue;
        //return privatevalue;
      }
    
    }

    -- I commented most of it out for debugging...

    So, am I missing something such that the files are not included properly? Or is there some other obvious bug in there?

    any thoughts appreciated!
    Last edited by Ken Fitlike; 09-06-2006 at 12:45 PM. Reason: code tags added

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie question
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-13-2009, 11:10 PM
  2. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  3. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  4. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  5. Primary colors question
    By Robin Hood in forum C++ Programming
    Replies: 8
    Last Post: 07-25-2002, 04:30 AM