Stupid Question for new C prog

This is a discussion on Stupid Question for new C prog within the C Programming forums, part of the General Programming Boards category; I've been working a lot in c++ and now i have to write my assignment in C. Can C use ...

  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,167
    No and yes.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    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,167
    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-03-2005, 11:17 PM
  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, 07:22 PM
  5. stupid question
    By maes in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 11-08-2001, 10:48 AM

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