473,413 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

2Questions:The double semicolon and right way to store classes

1) I know that when I create a class I can access its instance methods
(functions) through the sintax
classname.method(parameters);
so I'm asking you: what does the std::cout means.. what is this sintax
telling about the relation between the "std" and the "cout" ? I hope I
explained my self..

2) I'd like to create a class with its methods and private data.. I
see that most of the time the methods are specified in a cpp file
while the "class interface" (I'm probably thinking in a java way) that
specifies which methods are included and if they're private or public,
is included in a header file: for istance:

// FILE MyClass.h
class MyClass{
private:
method1();
int [] ...;
public:
MyClass();
MyClass(....);
method2()
};

// FILE MyClass.cpp
MyClass::MyClass(){
...
}
......

then I can make a main in a third file and tells the compiler to
include the two file MyClass.cpp and MyClass.h ?? Is this the right
way to work out things?
Thanks in advance

May 17 '07 #1
4 2538
in******@gmail.com wrote:
1) I know that when I create a class I can access its instance methods
(functions) through the sintax
classname.method(parameters);
so I'm asking you: what does the std::cout means.. what is this sintax
telling about the relation between the "std" and the "cout" ? I hope I
explained my self..
'A::B' means that 'B' is declared _inside_ 'A'. In your particular case
'cout' [object] is declared inside 'std' [namespace].
2) I'd like to create a class with its methods and private data.. I
see that most of the time the methods are specified in a cpp file
while the "class interface" (I'm probably thinking in a java way) that
specifies which methods are included and if they're private or public,
is included in a header file: for istance:

// FILE MyClass.h
class MyClass{
private:
method1();
int [] ...;
public:
MyClass();
MyClass(....);
method2()
};

// FILE MyClass.cpp
MyClass::MyClass(){
...
}
.....

then I can make a main in a third file and tells the compiler to
include the two file MyClass.cpp and MyClass.h ?? Is this the right
way to work out things?
Usually, yes.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 17 '07 #2
in******@gmail.com wrote:
1) I know that when I create a class I can access its instance methods
(functions) through the sintax
classname.method(parameters);
so I'm asking you: what does the std::cout means.. what is this sintax
telling about the relation between the "std" and the "cout" ? I hope I
explained my self..
The thing at the left of :: is a class or a namespace, while the
thing at the left of . is an object (ie. an instance of a class).
That's the difference.

When you write "std::cout" you know that "std" is the name of either
a namespace or a class (could well be either one), and "cout" is
declared inside it. If you wrote "std.cout" it would mean that you
have an object (a class instance, ie. a "variable") which name is
"std", and the class from which this "std" is an instance has something
inside it named "cout".
May 17 '07 #3
in******@gmail.com wrote:
1) I know that when I create a class I can access its instance methods
(functions) through the sintax
classname.method(parameters);
so I'm asking you: what does the std::cout means.. what is this sintax
telling about the relation between the "std" and the "cout" ? I hope I
explained my self..
Here 'std' is a namespace, so std::cout means "use the cout
symbol defined in the cout namespace. The "::" operator is
also used for classes when you access _static_ methods.
I believe that in Java you access static methods with a '.',
just like normal methods. In C++ you use "::", as in
MyClass::my_static_method();
2) I'd like to create a class with its methods and private data.. I
see that most of the time the methods are specified in a cpp file
while the "class interface" (I'm probably thinking in a java way) that
specifies which methods are included and if they're private or public,
is included in a header file: for istance:

// FILE MyClass.h
class MyClass{
private:
method1();
int [] ...;
public:
MyClass();
MyClass(....);
method2()
};

// FILE MyClass.cpp
MyClass::MyClass(){
...
}
.....
That's the typical thing to do, unless you're working
with templates.
then I can make a main in a third file and tells the compiler to
include the two file MyClass.cpp and MyClass.h ?? Is this the right
way to work out things?
Almost. You include the '.h' file, but you _don't_ include the
..cpp file, you just compile the two (main.cpp and MyClass.cpp)
together (or link them together later). So with a g++ compiler this
would look like:

g++ main.cpp MyClass.cpp

If you are working in a project-based environment or use a
Makefile, this is usually done for you. Anyway, the thing is
you usually don't "#include" cpps inside other cpps, you
just tell the compiler there are more than one cpps.

HTH,
- J.
May 17 '07 #4

Jacek Dziedzic <ja************************@gmail.comwrote in message ...
>
Here 'std' is a namespace, so std::cout means "use the cout
symbol defined in the cout namespace.
Typo, S/B:

Here 'std' is a namespace, so std::cout means "use the cout
symbol defined in the *std* namespace.

Don't want to confuse newbies, do we? <G>

--
Bob R
POVrookie
May 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: big vinny | last post by:
Hi I've been writing some serializing functions to load/store classes into db tables. There appears to be 2 ways of doing it, 1) iterative, derived classes store their parent's data before...
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
3
by: Pablo Salazar | last post by:
Hi People Few day ago, somebody sent me this code. ArrayList al = new ArrayList(); //Insertar datos en la lista: al.Add("Ejemplo1"); al.Add("Ejemplo2"); It can store two string in...
8
by: Steve1 via DotNetMonster.com | last post by:
Hi all, I'm new to C# and could do with alittle help. I'm currently producing a data conversion app. So far this app only has a Win form which is the user interface. I am finding this file...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
1
by: Jay Hamilton | last post by:
Hello, I am running into an invalid address alignment error on an HPUX box when I attempt to lookup a value in a STL map. The argument being passed in is a double, which is accessed from a...
4
by: IceMan | last post by:
Hello I am getting some odd answers when i use doubles in c# 0.55-0.5 = 0.050000000000000044 why am i not getting 0.05
2
by: Derek Hart | last post by:
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName) I want to format this and store it into a string. I have formatting stored in a database, such as "$#,##0.00"
6
by: Nathan Sokalski | last post by:
I know that Single and Double can only store values that can be stored as x/2^y, such as 0.5 and 0.125. But when they attempt to store values such as 0.1 or 0.2 whose exact value cannot be stored,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.