Narue 5,707 Bad Cop Team Colleague

How is Position defined?

Narue 5,707 Bad Cop Team Colleague

So when I call "heapDelete(HeapItemType& rootItem)" function in the driver file..
I don't know what to pass as argument.

It looks like you're just saving the top of the heap before removing it. rootItem would be any temporary variable you're using in your code:

while (!h.heapIsEmpty()) {
    HeapItemType top;

    h.heapDelete(top);
    std::cout<<"Removing '"<< top <<"'\n";
}

Some more information on HeapItemType would be useful though. Did you write this Heap class?

Narue 5,707 Bad Cop Team Colleague

>why did they use "Person *pPerson = new Person("Susan Wu", 32);"
There's no real reason in this example, and it's also best practice to delete any memory you new.

>where did ".length();" come from?
It's a member function of the std::string class.

>Also when "Rectangle *pRect" is put into a parameter, pRect
>is pointing at the address of the object rect, right?

That's correct.

Narue 5,707 Bad Cop Team Colleague

How many overloads of Spr_Blit do you have? If you have Spr_Blit(SDL_Surface*, SDL_Surface*) and Spr_Blit(SDL_Surface*, SDL_Surface*, SDL_Rect*=NULL) , you're introducing an ambiguity:

Spr_Blit(surface1, surface2); // Which overload to use?

Let's confirm everything you're trying to do rather than chase errors when there might be a more fundamental issue going on.

Narue 5,707 Bad Cop Team Colleague

I'm sorry, I didn't get what void* does.

It makes a a generic pointer. If you don't do something like this, cout will try to print a string of characters rather than an address.

anyway memory is still not increasing when the cout is there...

Then you did it wrong. Which is mildly humorous and somewhat sad seeing as how all you needed to do was copy and paste my line into your loop. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

You're printing the address of the pointer, not the value of the pointer. cout will interpret cout<< a as a C-style string though, so you need to cast it to void* to get the correct value:

cout<< (void*)a <<endl;
Narue 5,707 Bad Cop Team Colleague

Most image types have a specific format. If you insert bogus bytes into the format, it likely won't be recognized anymore. Your question is akin to "I smashed my cell phone, why doesn't it make calls anymore?". :icon_rolleyes:

jonsca commented: I find knocking my phone around helps to reseat the components to the board. ;) +7
Narue 5,707 Bad Cop Team Colleague

Why don't you post the code you've tried that doesn't work? We can show you where the problem is.

Narue 5,707 Bad Cop Team Colleague

What do these update methods do?

Narue 5,707 Bad Cop Team Colleague

Can the compiler go one step further and notice that foo() will never get called and hence just delete it so we're now here?

No, and the reason is because foo has external linkage (a poor choice of defaults, in my opinion). It might be used in another translation unit, and introspection between translation units is pretty darn expensive. If you give foo internal linkage by qualifying it as static, then the compiler could potentially do something.

VernonDozier commented: Thanks. +13
Narue 5,707 Bad Cop Team Colleague

Let me try again, this time without the brain fart. :)

The presence of a function call in a short circuited expression is generally difficult to optimize, but the presence of a constant and a short circuit that doesn't depend on the function call helps quite a bit. if (1 || foo()) can be optimized like so:

// Conditional removed
{
    cout<<"Hello World\n";
}

Due to the short circuiting of the || operator and the fact that the left hand side is a constant, the compiler can determine what to do at compile-time. In this case, the condition is true, foo doesn't need to be called, and the body of the conditional is always executed.

On the other hand, if (foo() || 1) can be optimized like this:

// Conditional removed
foo();
{
    cout<<"Hello World\n";
}

foo still needs to be called, but its result in the conditional isn't important due to the presence of a constant as the right hand side. As you know, the result of an || test is true if either side is true, so in this case the compiler can determine at compile-time that the result is true.

If it were an && test, that would be a different matter because the result depends on the value returned by foo, and it's quite a bit harder to deterministically figure out that foo returns true with a general algorithm.

Narue 5,707 Bad Cop Team Colleague

An unresolved external error is typically telling you that you've declared but not defined a function. In this case, the constructor for your Tree class. I notice that your destructor isn't implemented either, unless you're defining them in a separate file.

Narue 5,707 Bad Cop Team Colleague

But my doubt is that if a linked list has a loop, then wouldn't it be a circular linked list?

Not necessarily. This is a circular linked list:

a -> b -> c -> d -+
^                 |
|                 |
+-----------------+

This is a list with a loop, but it's not a circular linked list because the last node doesn't link back to the first node, it links to a node somewhere in the middle:

a -> b -> c -> d -+
          ^       |
          |       |
          +-------+

If yes, then the loop can be found by testing each node's address field with NULL.

How do you know when to stop looking? That's the point of the question.

Narue 5,707 Bad Cop Team Colleague

>> if(foo())

But Hello World should be displayed regardless of the return value of foo(), and the || 1 causes that. So you can't just toss out that or condition.

True. I'll blame an early morning brain fart. :D

Fbody commented: :) You're allowed one once in a while. ;) +5
jonsca commented: Regardless, I want a refund of today's ticket price ;) +7
Narue 5,707 Bad Cop Team Colleague

>> since your first operand of || was true, it skipped the foo() call in the first example.

That part I understand and expected. However, I expected the second part to also output 0. From the link, I see that both "left to right evaluation" and "short-circuiting" are mandated (thanks for the link. Good discussion on it). I was expecting a difference between RUN-time and COMPILE-time behavior though. Nothing really needs to be evaluated at all at runtime does it? It seems to me that a smart compiler should change this:

if(foo() || 1)

to this:

if(1)

and then just delete lines 15, 16, and 18 altogether as an optimization?

foo has a side effect, so the compiler can't just throw out the call without changing the program's behavior, and removing the call deterministically is rather difficult. However, if one side of an && or || is a constant, it's easy to ignore. So in both cases I would expect the optimizer to produce at least this:

#include <iostream>
using namespace std;

int a = 0;

int foo()
{
    a++;
    return a;
}

int main()
{
    if(foo())
    {
        cout << "Hello World\n";
    }
	
    cout << a << endl;
    return 0;
}

The fact that a isn't qualified as volatile gives the compiler some leeway for trickery, but I wouldn't rely on it.

Narue 5,707 Bad Cop Team Colleague

>if(insertedPlayer < current)
You're comparing pointers, not the "id" data member.

Narue 5,707 Bad Cop Team Colleague

No it isn't.

Yes, it is. I don't care what links you post, my source is the C++ standard. And unless you're terribly familiar with it, I strongly suggest you don't argue the finer points of the standard with me, though you're welcome to confirm that I'm correct. ;)

In particular, we're referring to the section tagged depr.c.headers:

1 For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 151.

Table 151 — C headers
<assert.h> <float.h> <math.h> <stddef.h> <tgmath.h>
<complex.h> <inttypes.h> <setjmp.h> <stdio.h> <time.h>
<ctype.h> <iso646.h> <signal.h> <stdint.h> <uchar.h>
<errno.h> <limits.h> <stdarg.h> <stdlib.h> <wchar.h>
<fenv.h> <locale.h> <stdbool.h> <string.h> <wctype.h>

2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).

3 [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header <stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. —end example ]

This …

Narue 5,707 Bad Cop Team Colleague

Sorry, I thought it would be obvious it's not in the std namespace.

That's not obvious at all because it is in the std namespace when you use <cctype>.

Narue 5,707 Bad Cop Team Colleague

It means buffer overflow. Check your pointers and verify your indexes.

Narue 5,707 Bad Cop Team Colleague

You wrote past the end (or beginning) of your dynamic memory and corrupted any bookkeeping data required by the heap manager.

Narue 5,707 Bad Cop Team Colleague

Do you have a handle on C++ fundamentals as well as the primary algorithms and data structures? If not, you'd best focus on those things for a bit. Once you get into real world development, strong fundamentals will be your biggest asset. And if you jump in too soon, you'll either be overwhelmed, or end up learning a lot of bad habits from being forced to work around a lack of fundamentals.

Narue 5,707 Bad Cop Team Colleague

Before looking for ways to do this, maybe you should consider why you want to do it in the first place. Bitwise operations not working on floating-point isn't much of an issue because most of the time it's nonsensical.

vineeshvs commented: i usually get good replies from narue +1
Narue 5,707 Bad Cop Team Colleague

cout is smart about types. If you try to print a char, it will be interpreted as a character rather than a small integer. If you copy that value into an int object and print that cout will no longer interpret it as a character. You're seeing the integer value of the characters rather than the character representation.

Try changing int n0,n1,n2,n3,n4; to char n0,n1,n2,n3,n4; .

Narue 5,707 Bad Cop Team Colleague

tolower is in <cctype> and is a C function.

If you think there's a problem, it's best to just say what you think it is.

once I read it into a char array, I saw that it was null-terminated

That's good. Working without any kind of formatting is either tricky or impossible, and I'm not a fan of either. ;)

Narue 5,707 Bad Cop Team Colleague

Instead of worker.abort(), use this:

keybd_event(VK_RETURN, 0x3d, 0, 0);
keybd_event(VK_RETURN, 0x3d, KEYEVENTF_KEYUP, 0);
worker.join();

The problem was that stdin was locked by getch, and terminating the thread didn't release the lock. The simplest solution I can think of is signaling a keyboard event to unlock stdin and stop the thread normally rather than abort it.

Your code is somewhat scary too, but I'll refrain from overloading you with information.

Narue 5,707 Bad Cop Team Colleague

You have a dictionary of words somewhere, right? My first attack would be to put the dictionary into a trie, with a special search that returns the end of the first complete match from the end of the most recent match. For example given a very limited dictionary:

#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <climits>

class trie {
    struct node {
        char key;
        node *link[CHAR_MAX + 1];
    public:
        node(char key): key(key)
        {
            std::fill_n(link, CHAR_MAX + 1, (node*)0);
        }
    } *root;
public:
    trie(): root(0) {}

    void add(const std::string& s)
    {
        node **it = &root;

        if (*it == NULL)
            *it = new node(0);

        for (std::string::size_type i = 0; i < s.size(); ++i) {
            char key = std::tolower(s[i]);

            if ((*it)->link[key] == 0)
                (*it)->link[key] = new node(key);

            it = &(*it)->link[key];
        }
    }

    std::string::const_iterator match(const std::string& s, std::string::const_iterator& begin)
    {
        std::string::const_iterator end = begin;
        node *it = root;

        while (end != s.end() && it->link[std::tolower(*end)] != 0)
            it = it->link[std::tolower(*end++)];

        return end;
    }
};

trie initialize_dictionary()
{
    const char *words[] = {
        "aardvark","apple","banana","bicycle","cobra"
    };
    trie trie;

    for (std::size_t i = 0; i < sizeof words / sizeof *words; i++)
        trie.add(words[i]);

    return trie;
}

int main()
{
    trie dict = initialize_dictionary();
    std::string s = "aardvarkapplebananabicyclecobra";
    std::string::const_iterator begin = s.begin();
    std::string::const_iterator end;

    for (std::string::const_iterator begin = s.begin(); begin != s.end(); begin = end) {
        end = dict.match(s, begin);
        std::cout<< s.substr(begin - s.begin(), end - begin) <<'\n';
    }
}
Narue 5,707 Bad Cop Team Colleague

However, when I type "home" it prints the statement in the getpath() method.

If the strings are equal, strcmp will return 0. You're always checking if the result is greater than 0 rather than equal to 0.

Narue 5,707 Bad Cop Team Colleague

fgets includes the trailing newline, so when the user types "pwd", the resulting string is actually "pwd\n". Try removing the newline after your fgets:

if (fgets(text, sizeof text, stdin) != NULL)
    text[strcspn(text, "\n")] = '\0';
Narue 5,707 Bad Cop Team Colleague

Try creating a new thread for accepting input and manage the timeout in your main:

#include <windows.h>

namespace jsw {
    namespace threading {
        class auto_event {
        public:
            auto_event(): _event(CreateEvent(0, false, false, 0)) {}

            BOOL wait(DWORD timeout = 1) const
            {
                return WaitForSingleObject(_event, timeout) == WAIT_OBJECT_0;
            }

            BOOL set() { return SetEvent(_event); }
        private:
            HANDLE _event;
        };

        class thread {
        public:
            static thread start(
                LPTHREAD_START_ROUTINE fn, LPVOID args = 0, 
                DWORD state = 0, DWORD timeout = 5000)
            {
                return thread(CreateThread(0, 0, fn, args, state, 0), timeout);
            }

            static void sleep(DWORD milliseconds) { Sleep(milliseconds); }
            static void exit(DWORD exitCode) { ExitThread(exitCode); }
        public:
            thread(HANDLE thread, DWORD timeout): _thread(thread), _timeout(timeout) {}
            ~thread() { CloseHandle(_thread); }

            DWORD exit_code() const
            {
                DWORD exitCode = NO_ERROR;

                GetExitCodeThread(_thread, &exitCode);

                return exitCode;
            }

            HANDLE handle() const { return _thread; }
            BOOL is_alive() const { return exit_code() == STILL_ACTIVE; }
            DWORD join() { return WaitForSingleObject(_thread, _timeout); }
            DWORD suspend() { return SuspendThread(_thread); }
            DWORD resume() { return ResumeThread(_thread); }
            BOOL abort(DWORD exitCode) { return TerminateThread(_thread, exitCode); }
        private:
            HANDLE _thread;
            DWORD _timeout;
        };
    }
}

#include <iostream>
#include <string>

DWORD WINAPI get_password(LPVOID args)
{
    using namespace jsw::threading;

    std::string *s = (std::string*)((LPVOID*)args)[0];
    auto_event *e = (auto_event*)((LPVOID*)args)[1];

    getline(std::cin, *s);
    e->set();

    return NO_ERROR;
}

int main()
{
    using namespace jsw::threading;

    std::string password;
    auto_event e;
    LPVOID args[2] = {&password, &e};

    thread worker = thread::start(get_password, args);

    if (e.wait(5000))
        std::cout<<'\''<< password <<"' was correct\n";
    else {
        worker.abort(NO_ERROR);
        std::cout<<"Invalid password\n";
    }
}
Narue 5,707 Bad Cop Team Colleague

So close, yet so far. Isn't the preprocessor a bitch to work with for anything but the simplest of replacements? ;)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define XSTR(x) #x
#define STR(x) XSTR(x)

int main()
{
        FILE *fp;
        char filename[30];
#ifdef CORE
        strcpy(filename,STR(CORE));
#else
#error "Must provide ...."
#endif
        fp = fopen(filename,"w");
        printf("%s\n",filename);
        if(fp == NULL)
                printf("Can not open File\n");
}

Double quotes in the command line will be consumed by the shell, so you need to stringize the macro value to use it in string context. The STR macro gets that value and passes it on to another helper macro, XSTR, which uses the stringize preprocessor operator. Note that if you don't use this delegation and just use the stringize operator directly:

#define STR(x) #x

STR(CORE) will produce "CORE" rather than "log.txt".

Narue 5,707 Bad Cop Team Colleague

Thanks for those kind words. :)

To answer your question, I prefer Visual Studio with the Comeau front end and Dinkumware standard library implementation. Though that doesn't stop me from using several compilers on a regular basis. It's a habit I got into for maximum portability.

Narue 5,707 Bad Cop Team Colleague

Let's assume for a moment that you don't need a granularity that would eat up a lot of CPU time (say a 1 minute poll/sleep schedule). You really don't need a timer, just a running count of uptime units as long as the process is running:

int minutes_up()
{
    static int minutes = 0; // Resets on program restart

    if (process_running(process_name))
        ++minutes;

    return minutes;
}

If the process isn't running and you only care about totals, there's nothing to count.

Narue 5,707 Bad Cop Team Colleague

What's the ultimate goal here? Are you just trying to report the uptime of a process, or is this more of a control to keep the process from running continuously for a certain amount of time?

Narue 5,707 Bad Cop Team Colleague

It was here that I was told that I was shown that, and it doesn't give any errors at all.

Most likely your compiler is being helpful and ignoring the typedef keyword. Turn up your warning level and you'll probably see some mention of it. This is the correct syntax:

typedef struct <structure name>
{
    <members>
} <typedef name>;

Though that's largely irrelevant as typedefing a structure is unnecessary in C++ for the use it was devised in C (to avoid typing the struct keyword everywhere). The compiler does it for you implicitly.

Narue 5,707 Bad Cop Team Colleague

In other words, you're completely incompetent. Massive ideas but an inability to follow through with them makes you utterly valueless. Then again, you're very obviously a troll who has no interest in following through with massive ideas. Rather, you're simply trying to get jollies out of wasting people's time.

Saith commented: Just bc we all love trolls. +1
Narue 5,707 Bad Cop Team Colleague

the other half doesn't show anything

That's because you're caught in an infinite loop. :icon_rolleyes:

and also i don't understand what you mean by
>" You used = where == was intended."

>while(swapped=true){
should be

while(swapped==true){
Narue 5,707 Bad Cop Team Colleague

>int array;
This won't work in standard C++. Array sizes must be compile time constants, and your size variable is not. If it compiles, you're relying on a compiler extension which isn't good when learning the language.

>bubblesort(array[],size);
The brackets aren't necessary when referring to the array object itself:

bubblesort(array, size);

Also, swap and bubblesort don't return a value but are defined to return int. And your bubblesort has a bug that will cause an infinite loop. You used = where == was intended.

Narue 5,707 Bad Cop Team Colleague

Did you search google? There's a lot of information on agile already out there.

Narue 5,707 Bad Cop Team Colleague

There's no need to copy members individually. You can simply copy the structure objects:

timesheet[j] = timesheet[j + 1];
Narue 5,707 Bad Cop Team Colleague

Sorry, I didn't give enough details.

That's correct. Presently you're using monthly to accumulate the expenditures, which in this case will cause the loop to stop after the value exceeds 12. Try writing this program under the assumption that it only manages a single month, that should make the problem simpler.

Narue 5,707 Bad Cop Team Colleague

Yes, you can absolutely get help.

Narue 5,707 Bad Cop Team Colleague

You want a random shuffle. Simply filling the array with random values will very likely produce duplicates. Shuffling multi-dimensional arrays is harder, so the usual advice is to shuffle a one-dimensional array and then copy the results into your final two-dimensional array:

#include <stdio.h>
#include <stdlib.h>

void swap(int *a, int *b)
{
    int save = *a;

    *a = *b;
    *b = save;
}

void random_shuffle(int *a, size_t n)
{
    size_t i;

    for (i = 0; i < n - 1; i++)
        swap(&a[i], &a[i + (rand() % (n - i))]);
}

#define M 4
#define N 4

int main(void)
{
    int a[M][N] = {
        {0,  1,  2,  3},
        {4,  5,  6,  7},
        {8,  9,  10, 11},
        {12, 13, 14, 15}
    };
    int i, j;

    random_shuffle(&a[0][0], M * N);

    for (i = 0; i < M; i++) {
        for (j = 0; j < N; j++)
            printf("%3d", a[i][j]);
        putchar('\n');
    }

    return 0;
}

For fun: The above code has a very subtle problem! See if you can find it.

Narue 5,707 Bad Cop Team Colleague

Hello

Using :

cout << "enter 5 letter";
getline(cin, letter);

executes fine but when running PC- Lint:
getline(cin, expectedLabel): error 534: (Warning -- Ignoring return value of function 'std::getline(std::basic_istream<char,std::char_traits<char>> &, std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
error 830: (Info -- Location cited in prior message)

I was wondering if anyone could tell me the problem with getline and is there an alternitve i do wish to enter 5 letters

It's a false positive. Lint programs are designed to be persnickety, which often means warning about problems that simply don't exist. Many times you'll call a function that returns a value for the side effect rather than the return value. getline in this case, has a side effect of reading a string from the first argument into the second argument. For convenience purposes it also returns a reference to the stream (the first argument), but ignoring that return value won't cause any problems.

To silence the warning you can cast the function call to void:

cout << "enter 5 letter";
(void)getline(cin, letter);

However, that's assuming you're properly checking the stream state later on. If getline fails for some reason, you can use the stream state to determine what happened and avoid potential errors from assuming success. This is a case where the return value is useful:

cout << "enter 5 letter";
if (!getline(cin, letter)) 
{
    // Handle the error
}

Which is equivalent to, and less verbose than this:

cout << "enter 5 letter";
(void)getline(cin, letter);

if (!cin) {
    // …
Narue 5,707 Bad Cop Team Colleague

Backslash in a string literal begins an escape character. If you want a literal backslash, double them up:

infile.open("C:\\201\\PigLatin.txt");

Alternatively, you can use forward slashes. That works too:

infile.open("C:/201/PigLatin.txt");

missing function header (old-style formal list?)

This means the compiler thinks you're starting a function body. Usually it's related to mismatched braces, but it's hard to say for sure with the little bit of code you posted.

ravenous commented: Good tip about the forward slashes +6
Narue 5,707 Bad Cop Team Colleague

1. Do we have static classes in C++?

Since this question was given to you by a Java programmer, you have to consider what a static class is in Java and then see if C++ supports the same behavior. In Java, a static modifier is only allowed on nested classes, and the resulting behavior is that the nested class can be used without an object of the nesting class:

class Outer {
    public static class StaticClass {}
    public class InnerClass {}
}

class Test {
    // Works
    private Outer.StaticClass _staticObj = new Outer.StaticClass();

    // Error
    private Outer.InnerClass _innerObj = new Outer.InnerClass();

    // Outer object required to use InnerClass
    private Outer dummy = new Outer();
    private Outer.InnerClass _innerObj2 = dummy.new InnerClass();
}

Java's static behavior is what C++ uses by default, so static classes in this context aren't necessary:

class Outer {
public:
    class StaticClass {};
};

class Test {
    Outer::StaticClass _staticObj;
public:
    Test(): _staticObj() {}
};

It's actually the inner class behavior from Java that isn't available in C++. ;)

3. Is this the name given to classes that should not be allowed instantiation?

Not in Java. Other languages apply different meanings to static when applied to a class. C#, for example, uses your interpretation. A static class in C# cannot be instantiated and contains only static members. In C++ that would be accomplished by making all members static and declaring a private constructor.

4. If so, how is it different from abstract classes?

An abstract …

jonsca commented: Nicely tied together :) +6
Narue 5,707 Bad Cop Team Colleague

Ah, I see. So, if one were to redefine the assignment operator for, say, integers as int &operator=(const int &right) , then the const_reference version would be called? (this isn't something I'm suggesting that I might try to do, just an example)

Well, you can't do that because overloading operators on built-in types isn't allowed. But I get what you mean. The const/non-const selection really only matters if you have two overloads that only differ in the constness of the member function[1], ie:

int& operator[](int i)       { return _base[i]; }
const int& operator[](int i) const { return _base[i]; }

In the presence of both, the constness of this will determine which operator is used. If this is const, the const overload will be used. If this is not const, the non-const overload will be used. If you just have a member function that's const, it's slightly different:

// No non-const overload
const int& operator[](int i) const { return _base[i]; }

In this case, there's no choice to be made, so whether this is const or not, the const member function will always be selected because a const member function can be called on a non-const object. A const member function simply says that the member function won't change the state of the object.


[1] Note that return types aren't considered in overloading, so the difference between int& and const int& is irrelevant to overload resolution.

Narue 5,707 Bad Cop Team Colleague

But what about std::vector ?

What about it? If you used vector instead of Array in your example, the non-const at would still be chosen. You ask the question as if vector does something different.

Is it the case that only one of them is ever actually used by the compiler

The const/non-const overloads are intended strictly to handle const/non-const objects. The constness of your object determines which is called.

Narue 5,707 Bad Cop Team Colleague

However, const_reference at() const never gets called. Can anyone see why this is?

None of your objects are const. The compiler isn't exactly going to say "oh, that call is on the right hand side of an assignment, the programmer must want me to use the const version of this member function even though the non-const version is a perfect match".

You need to come up with another way of differentiating between the overloads than magic. Maybe perform your special logic for the at member functions and just do regular indexing for the subscript operators? Or perhaps an extra parameter that defaults to your most common behavior:

reference at(const unsigned n_, copy_semantics = DEEP);
const_reference at(const unsigned n_, copy_semantics = DEEP);
a.at(1) = 3;
a.at(1) = b.at(1, SHALLOW);
Narue 5,707 Bad Cop Team Colleague

Without putting too fine a point on it, local objects are stored on the stack and dynamically allocated objects are stored on the heap:

class foo { int x; }

int main()
{
    foo bar; // bar is stored on the stack
    foo *baz; // baz is stored on the stack

    baz = new foo; // *baz is stored on the heap

    // Necessary because *baz isn't released on scope exit
    delete baz;
}

It can get more complicated, but that should serve as an example of how the location in memory depends on how an object is created.

ahtaniv commented: Clear explanation with example :) +1
Narue 5,707 Bad Cop Team Colleague

My understanding is that the Objects created are stored in the heap segment.

Your understanding is incorrect. The location for an object depends on how it's created.

What if the objects are created for a class with static data members?

The static data members are stored separately from instance data members. Since you mentioned the heap segment, I'll assume a certain common executable format and say that if the static data member is initialized, it goes in the data segment, and if it's uninitialized, it goes in the BSS segment. Instance data members will depend on how the object is created. If it's dynamically allocated such as with new, then you're likely looking at the heap segment, though that's not guaranteed.