Find the answer to your Linux question:
Results 1 to 5 of 5
I learned BASIC as my first language so I'm used to Subroutines and Functions, but nothing really like classes and objects. I'm really confused as to why this happens: class ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    32

    Confused on object oriented programing (C++)


    I learned BASIC as my first language so I'm used to Subroutines and Functions, but nothing really like classes and objects. I'm really confused as to why this happens:


    class her {
    public:
    cout << "hi";
    };


    I get an error at the cout saying "This declaration has no storage class or type specifier"

    Now it could be a syntax error for all I know. I knew a little bit of java and got classes working in it so I don't see what's wrong. Just for reference here is my main:


    #include "stdafx.h"
    #include <stdlib.h>
    #include <iostream>
    using namespace std;

    void main()
    {
    her obj;
    her();
    system ("pause");
    }


    If Everything I did is a total mess, I don't expect you guys to teach me, but if you could tell me a great website, or better yet, recommend a book for C++ that would be great.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    you can't put code like that into the declaration of a class, you would have to define a function and put it in the body of the function

    cplusplus.com - The C++ Resources Network

  3. #3
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    The format of the class is wrong. I have always used C++:The Complete Reference. I am sure there are a bunch of books that are just as good, not to mention other free web sites.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    As a C++ newbie, you might want to get a copy of Deitel & Deitel "C++ How To Program" published by Prentice-Hall. It also contains an intro to object-oriented design with UML. In any case, it is a decent introductory book to the subject.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Aug 2010
    Posts
    32
    OOP as a whole concept seems to baffle me for some reason though. It did the same thing in Java. I'll check out those sites and books though, thanks for the help guys, hope I figure this out soon.


    If I don't though I do suppose I'll have an actual teacher teaching it in college but I'm no very patient :X

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •