Thread: Stupid Question for new C prog

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    11

    Stupid Question for new C prog

    I've been working a lot in c++ and now i have to write my assignment in C.
    Can C use classes (like be able to create new data types with public and private members?) Or do i basically have to do everything using structures?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    No and yes.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    C does not support classes; in fact, C++ was originally called C with Classes. Structs are available though.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The only difference in C++ between a class and a struct is its default visibility of its members anyway. Classes default to private, and structs default to public. Other than that, in C++, they're identical.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    In C, use structs as classes. When you want to make a member function, declare it as an independent function, and make it take an additional "this" pointer.

    and instead of
    Code:
    SomeClass c;
    c.someMember(1, 2);
    do
    Code:
    struct SomeStruct c;
    someMember(&c, 1, 2);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. stupid question
    By maes in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 11-08-2001, 11:48 AM