Narue 5,707 Bad Cop Team Colleague

Done with the idiot troll. Thanks for playing.

*plonk*

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

Honestly, can it all be done with machine language and native graphics card and sound card instructions and nothing more?

Yes. But writing machine code directly and interfacing directly with hardware is both difficult and tedious. I assume since you're excessively insane about not using the efforts of others that hardware drivers are out of the question. In that case you'd also need to write your own drivers, and your own OS to host the drivers, and your own hardware to host the OS.

No rational person would take this to the extremes you've gone, so I can only assume that you're trolling with these "can I do it?" questions.

Narue 5,707 Bad Cop Team Colleague

I tried to include both headers, did both required tasks but only one of the windows opens.

There can only be one entry point into the program. For a console project that entry point is the traditional main(). For a Windows project, the entry point is WinMain. If you want a console window to use in your application, you can open one with little difficulty:

#include <string>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     lpCmdLine,
                   int       nCmdShow)
{
    if (AllocConsole()) {
        std::string s = "I made a console window!";
        DWORD n;
        char c;

        WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), s.c_str(), s.size(), &n, 0);
        ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &c, 1, &n, 0);
    }
}

Attaching the standard C++ handles to the new console window so you can take advantage of cin and cout is marginally more difficult (and involves a few assumptions), but nothing terrible:

#include <iostream>
#include <string>
#include <cstdio>
#include <windows.h>
#include <io.h>
#include <fcntl.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     lpCmdLine,
                   int       nCmdShow)
{
    if (AllocConsole()) {
        int ifd = _open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
        int ofd = _open_osfhandle((intptr_t)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);

        *stdin = *_fdopen(ifd, "r");
        *stdout = *_fdopen(ofd, "w");

        std::cout<<"I made a console window";
        std::cin.get();

        fclose(stdout);
        fclose(stdin);
    }
}

While the latter isn't documented as such anywhere to the best of my knowledge, the former is easily located on MSDN.

Narue 5,707 Bad Cop Team Colleague

You can implement operator== for your class, or alternatively use find_if, which takes a predicate:

#include <algorithm>
#include <functional>

struct id_match: public binary_function<A, int, bool> {
    bool operator()(const A& obj, int id) const { return obj.ID == id; }
};

//...

match = find_if(l.begin(), l.end(), bind2nd(id_match(), 999));

A regular loop isn't out of the question either:

list<A>::iterator it = l.begin();

while (it != l.end() && it->ID != 999)
    ++it;

if (it != l.end())
    it->name = new_name;

Of course, in your example the data members of the class are private, so some kind of accessor will be needed.

Narue 5,707 Bad Cop Team Colleague

I guess until that day comes I won't be happy with programming.

Sucks to be you then.

Narue 5,707 Bad Cop Team Colleague

Some people aren't cut out for programming. You might be one of those people. Or you might not, and you're just being melodramatic. We're our own worst critics as well, so it's possible that you understand more than you believe and hold yourself back by being too hard on yourself.

Narue 5,707 Bad Cop Team Colleague

You're dead wrong in thinking bad attitude is mainly associated with males.

It's not as much a bad attitude as being competitive and quick to lash out at perceived insults. Your behavior strikes me more as that of the average teenage dude.

I'm highly offended and actually hurt

I couldn't care less if you're offended or not.

Narue 5,707 Bad Cop Team Colleague

I know this is off-topic, but why did you assume I was male?

Unless you're talking about the snipped profanity, I don't see any such assumption in this thread. But it's generally a good assumption on this kind of forum. It's also easier to make an assumption and go with it than writing in a gender neutral manner. Finally, your attitude does suggest a younger male.

Fbody commented: yup +5
Narue 5,707 Bad Cop Team Colleague

I understand the validation would be a display of the entered date so the user can verify it is correct.

That's probably not a good assumption. More likely is that you're required to programmatically evaluate the date and determine if it's valid.

1. Does this declare a data type or variable?

A class definition introduces a data type.

2. What is public/private (I understand access control, but not understanding the benefits of using private)?

Then you don't understand access control. Think of it like this: the bank doesn't let you log into their system with full access because there's high risk of either someone breaking all kinds of stuff accidentally, or doing unscrupulous things like adding a few zeros to the end of their balance. You should have similar concerns with the classes you write.

3. I understand const = = constant, but don’t understand the results of using ?

It's another form of access control, except at the code level. const is a way of protecting yourself by disabling write access to an object.

4. Is there a difference between a class declaration and definition?

Yes. A class declaration only brings the name of a class into scope. A definition, on the other hand, provides enough information for objects to be created and used.

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

I don't really see how this would help. Either you know the material or you don't. A thread of interview questions won't change that. You might get lucky and be asked a question that shows up in this thread, but that's kind of like sleeping with the textbook under your pillow before a test.

Narue 5,707 Bad Cop Team Colleague

wrap your code in code tags.

<snip>

template <class T>
class myClass
{
T myMember;
}

template <class T>
T myClass<T>::getSomething(){return myMember;}

Oh, the irony.

Narue 5,707 Bad Cop Team Colleague

i was told objects can be created in C just like c++.

Objects are really just lumping data and functions that operate on the data into one package. In C you can't have member functions, but you can have pointers to functions:

#include <stdio.h>

typedef struct foo foo;

struct foo {
    int data;
    void (*add)(foo *self);
};

void foo_add(foo *self)
{
    ++self->data;
}

int main()
{
    foo obj = {0, foo_add};
    int i;

    for (i = 0; i < 10; i++) {
        obj.add(&obj);
        printf("%d\n", obj.data);
    }

    return 0;
}

The process is lower level than C++ in that you need to manually handle some of the things that C++ does for you, such as passing the this pointer to member functions and attaching member functions to each object on initialization.

Objects like this are easy. The complication is introduced when one wants to implement inheritance and polymorphism to C, which usually results in ridiculous abuse of the preprocessor. ;)

Narue 5,707 Bad Cop Team Colleague

No, it's not bad. Only C++ purists will rag on you about it, but they're in a world of their own anyway.

Narue 5,707 Bad Cop Team Colleague

If nothing else, your lack of shame is impressive.

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 question is that everyone says C/C++ is more powerful than many other languges e.g Visual basic but why is it more powerful.

Not everyone. Making such a claim is misleading because the definition of "powerful" hasn't been nailed down. Yes, C and C++ are both powerful languages, but other general purpose languages are also powerful. More powerful implies that the two languages being compared are in direct competition for all possible measures, which is certainly not the case with C/C++ and Visual Basic and is rarely the case in general.

As an example, Visual Basic is typically the language of choice[1] for developing GUIs on a Windows platform because it excels at that. Visual Basic is also surprisingly powerful in terms of Windows programming if you know what you're doing. But historically VB has been slower, so a common choice was to use VB at the front end and C++ at the back end. The two complement each other, and aren't in direct competition. A wise developer chooses the best tool for the given task.

Is it because of the pointers?

There's no single feature that makes or breaks a language as being "powerful". But pointers are indeed fundamental to the point where if one can't properly understand them, becoming truly proficient at C/C++ is impossible.

nowadays we usually have high speed Rams with atleast 2 GB and multiple core processors

More RAM and faster CPUs are a godsend for people who can't write efficient code. …

Narue 5,707 Bad Cop Team Colleague

Let's break it down a bit. A function has four parts:

  1. An identifier
  2. A return type
  3. A parameter list
  4. A body

The first three are combined to create the function's signature, and it looks like this:

<return type> <identifier>(<parameter list>)

The parameter list is enclosed in parentheses simply because that makes it easier your the compiler to determine where the list begins and where it ends. The return type may be void, to say that the function returns nothing.

The body of a function is where the work is done, and it's essentially a compound statement (a series of statements wrapped in braces). To return an actual value from the function, you use a return statement.

When you call a function, you specify the identifier and a list of arguments which match the parameter list.

int add(int a, int b)
{
    return a + b;
}

#include <iostream>

int main()
{
    int sum = add(1, 2);

    std::cout<< sum <<'\n';
}

The previous code defines a function called add (the identifier), with a parameter list containing two ints, and a return type of int. The body of the function adds those two parameters together and returns the sum.

When called, 1 is copied into the parameter called a, and 2 is copied into the parameter called b. After this happens, the body of the function is executed, and the return value is then copied into a new int in main called sum. …

Narue 5,707 Bad Cop Team Colleague

I believe there is lot of misunderstanding in your post Narue

You believe a lot of things that simply aren't true, as evidenced by your (I'll say it again) ignorant rant. Apparently you took the word "ignorant" as an insult, which is stupid.

also I really don't know what you have against me?

I had nothing against you until you started getting whiny. Now I'm finding you childish and annoying.

Why are those visual languages less productive?

Because any reasonably competent programmer can churn out working code much quicker than dragging and dropping icons into a visual designer.

Look at the Dreamweaver

  1. Dreamweaver is a far cry from a general programming language.
  2. A good use of visual designers is for user interfaces because it's simpler than back end logic and there's a direct correlation between the designer elements and the resulting interface.

there is no obstacle besides concurrency and stingy knowledge, I strongly believe that.

Then you're too stubborn to listen to reason and I won't waste any more of my valuable time.

Still I believe its just a matter of few years when somebody will finally start something like that.

These things already exist, genius. Go do a search on google.

Narue 5,707 Bad Cop Team Colleague

Is that so bloody hard?

What an ignorant rant. Of course visual programming languages have been tried before. Some are even in active use, but for the most part they're awkward and less productive than the code based languages such that serious developers don't care enough to push for more. Not to mention the inherent difficulty in defining a generic visual language that's powerful enough to be useful without being so low level that you end up with the drag and drop version of assembly.

Tcll commented: haha, that's very similar to what I'm working on for recompilation purposes, but indeed your point is flawless. :) +4
Narue 5,707 Bad Cop Team Colleague

I don't understand what is wrong with writing code like: Wood a, b, c; (a * b) = c;

There's nothing wrong per se. It's generally frowned upon because when overloading operators, the general rule of thumb is "do as the ints do", or match the semantics of built-in types. If the same operators have different semantics on your custom type than they do on built-in types (or standard library types), you make understanding the code more difficult.

Fbody commented: Good rule of thumb. I'll have to make sure I remember that one. :) +5
Narue 5,707 Bad Cop Team Colleague

I've seen the term used in two contexts:

  1. An algorithm for an undecidable problem. In other words, there's no proof that the algorithm will reach a conclusion in finite time.
  2. In reference to hypercomputation theory.
Narue 5,707 Bad Cop Team Colleague

nounnylee,

I am not sure what you are saying

He's saying "I want to spam the links in my signature and increase my page rank". The joke's on him though. Last I checked, signatures on Daniweb weren't visible to guests (including bots), so this attempt at spam fails miserably.

Nick Evan commented: True +0
Narue 5,707 Bad Cop Team Colleague

The code uses outdated and potentially dangerous techniques, and isn't robust at all. You can easily invoke undefined behavior by typing enough digits to overflow the signed int type. Further, it doesn't properly handle negative values.

To improve the code I'd offer three pieces of advice:

  1. Support the full range of int
  2. Pre-check for integer overflow
  3. Ditch the gotoxy stuff (the most you need for interactive control is a getch clone, everything else can be done with standard C)
  4. For maximum portability, use an intersection of the C89 and C99 standards
Narue 5,707 Bad Cop Team Colleague

Helpful hints, hmm. How about don't be lazy? It's not like someone walked up to you on the street and gave you this assignment when you know zilch about trees. You must have learned something in class before your teacher gave the assignment, so posting up the requirements without trying anything is the height of laziness.

Narue 5,707 Bad Cop Team Colleague

Try using printf("Greetings, human!"); (just a guess, honestly)

That's subtly different because you didn't include a newline at the end. While printf is the function you'll see most in hello world programs, puts works just fine.

Narue 5,707 Bad Cop Team Colleague

The following is a common error:

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

int main()
{
    std::string line;

    std::cout<<"Enter a line: ";

    if (getline(std::cin, line)) {
        std::cout<<"Before: "<< line <<'\n';

        // This is wrong!
        std::transform(line.begin(), line.end(), line.begin(), std::toupper);

        std::cout<<"After:  "<< line <<'\n';
    }
}

What's the problem? Unbeknownst to many, std::toupper is overloaded. There's the familiar version in <cctype> and another version in <iostream> with a second argument for the locale. So which of these is transform supposed to pick when you haven't specified the arguments? The answer is it's ambiguous, and shouldn't compile.

The following is correct:

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

struct upper_case {
    int operator()(int c)
    {
        return std::toupper(c);
    }
};

int main()
{
    std::string line;

    std::cout<<"Enter a line: ";

    if (getline(std::cin, line)) {
        std::cout<<"Before: "<< line <<'\n';

        // This is correct
        std::transform(line.begin(), line.end(), line.begin(), upper_case());

        std::cout<<"After:  "<< line <<'\n';
    }
}

By creating a function or function object which calls the version you want explicitly, the ambiguity is removed. Alternatively, you can use the locale-friendly version:

#include <locale>

struct upper_case {
    int operator()(int c)
    {
        return std::toupper(c, std::locale());
    }
};
mrnutty commented: Nice to know +7
Narue 5,707 Bad Cop Team Colleague

if you declare an empty class and then inside main you create an object of this class what is created?

A single byte. :) In the case of a class with no data members, the compiler will allocate sufficient space to give the object an address. On a side note, because there are no data members and no base classes, all of the special member functions are completely trivial and thus not generated implicitly.

Narue 5,707 Bad Cop Team Colleague

You're using integer arithmetic, any precision will be lost before the result is assigned to your float variable. Convert one of the operands to a floating-point type and it should work: ((float)end - start) / CLOCKS_PER_SEC .

Clinton Portis commented: muy bueno +6
Narue 5,707 Bad Cop Team Colleague

4.) There's nothing wrong with your codes. What's wrong with "Go To"? What matters is the purpose and the content of your program. Think of the people who will use the program.
Not all of them are knowledgable with C++ so why bother? It's not like they are going to see your codes.

You clearly have no experience writing software. Maintenance nightmares like this affect the end user through bugs and excessive time to delivery of updates and patches. In my experience, sloppy code is also often brittle and fails on a regular basis. That pisses off users too. :icon_rolleyes:

jember commented: Thank you... :) +1
Narue 5,707 Bad Cop Team Colleague

>while(!text.eof())
This is an off-by-one error because eof only returns true after you've attempted to read beyond end-of-file. So you'll have one final iteration of the loop where get fails, but you still process b (from the previous iteration). You can use the result of get as a condition, which is both correct and more concise:

while (text.get(b)) {
    // ...
}
Narue 5,707 Bad Cop Team Colleague

How is that "just plain stupid"? It looks fine to me. Of course, there are other ways to do it, but fscanf would work just fine.

If the input is guaranteed to have four words separated by '$', then an integer, it'll work fine (in an ugly way), but the example string doesn't strike me as strictly formatted, in which case fscanf would be a bad idea. What happens if another word is added, or a word is removed?

Narue 5,707 Bad Cop Team Colleague

I can't help but think data binding seems unnecessarily complicated...

Implement equivalent behavior manually a few times and you'll begin to see how data binding makes life simpler. Of course, there's quite a learning curve in my experience, because binding can create frustratingly difficult to fix bugs. But once you get a handle on it, I think binding is worth it.

isn't it simpler just to add them to the listview one by one as they're first read from the XML?

If it's just a matter of displaying read-only content, probably. But data binding also maintains updates to the underlying data. When you need to keep track of insertions, deletions, and data changes in existing records, the maintenance code grows significantly both in size and complexity.

Narue 5,707 Bad Cop Team Colleague

So do you have a general suggestion to make the code simpler?

Forget goto exists.

Narue 5,707 Bad Cop Team Colleague

One big decision you need to make in merging is whether it's destructive or not. Are you going to remove nodes from each list and add them to the result, or copy the data into new nodes?

Either way the merge works as a traversal. Select between the two lists based on some useful ordering as long as both lists are not empty. Only the selected list is moved forward. Once one list becomes empty, unconditionally copy the remaining list to the result. Consider the following:

node *merge(node *a, node *b)
{
    node *c = 0;

    while (a != 0 && b != 0) {
        if (a->info < b->info) {
            c = insert(c, a->info);
            a = a->next;
        }
        else {
            c = insert(c, b->info);
            b = b->next;
        }
    }

    while (a != 0) {
        c = insert(c, a->info);
        a = a->next;
    }

    while (b != 0) {
        c = insert(c, b->info);
        b = b->next;
    }

    return c;
}
Hojjat.Mojallal commented: It solved my problem +0
Narue 5,707 Bad Cop Team Colleague

so if i use this code my datatable will override with this select ststement

That's not correct. The select query is required by SqlCommandBuilder for generating insert, update, and delete statements. The select statement isn't run to refill the table unless you call the Fill method of your data adapter after updating. So da.Update(table) only runs insert, update, and delete statements.

threfore need a way without having a select query

You can build the SqlCommand objects for insert, update, and delete manually, then add them to the data adapter before calling Update. That has the same effect as using a SqlCommandBuilder, except it's more work on your part.

Narue 5,707 Bad Cop Team Colleague

Did you hit your head and get amnesia or something? I answered all parts of this exact question in the only other thread you've posted on Daniweb.

Narue 5,707 Bad Cop Team Colleague

>DNA Mate = *(testDNA.CrossoverMutate(testDNA2));
The copy constructor will be called here to initialize Mate with the dereferenced pointer. If you don't want that happening, make Mate a pointer as well:

DNA *Mate = testDNA.CrossoverMutate(testDNA2);
Narue 5,707 Bad Cop Team Colleague

Existential question: If room 5 doesn't exist, are the lights on? ;)

WaltP commented: Good point... +15
Narue 5,707 Bad Cop Team Colleague

I want to encrypt and decrypt a password using c#.net.

Don't encrypt your passwords. You should use a method that isn't reversible, which is why cryptographically secure one-way hashing is a common practice. Add a salt to the password (so identical passwords don't produce the same hash), then hash the combination a number of times. Add the unhashed salt to the hash, convert to a base 64 string for storage portability, and you're done. To check a password for validity, extract the salt and create a new hash with it, then compare to the stored hash:

using System;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;

class Application {
    public static void Main()
    {
        string pass = "some kind of password";
        List<string> stored = new List<string>();

        for (int i = 0; i < 10; i++)
            stored.Add(MungePassword(pass, null));

        foreach (string s in stored) {
            if (CheckPassword(s, pass))
                Console.WriteLine("Password is valid");
            else
                Console.WriteLine("Password is NOT valid");

            Console.WriteLine("\t'" + pass + "'");
            Console.WriteLine("\t" + s);
        }
    }

    private static string MungePassword(string password, byte[] salt)
    {
        if (salt == null) {
            // Create a random salt if one isn't provided
            salt = new byte[8];

            using (var crng = new RNGCryptoServiceProvider())
                crng.GetBytes(salt);
        }
        else if (salt.Length < 8)
            throw new ArgumentException("Salt must be at least 8 bytes");

        byte[] bytes = new UTF8Encoding().GetBytes(password);
        var saltedPass = new byte[bytes.Length + 8];

        // Combine the salt and password
        Array.Copy(bytes, saltedPass, bytes.Length);
        Array.Copy(salt, 0, saltedPass, bytes.Length, 8);

        var hash = new SHA256Managed();

        // Hash a suitably large number of times …
cale.macdonald commented: Good description on how it should be done +2
kvprajapati commented: Absolutely! +11
Narue 5,707 Bad Cop Team Colleague

Yes, it's possible. The destination array needs to be large enough to hold the replacement, and the process is rather manual. You'll shift everything to the right of the matching character to make a hole, then overwrite what was in the hole with the new data:

# Find 'e'
joey
  ^

# Shift everything after 'e' to make room for 3 characters
joe  y
  ^  ^

# Fill in the hole with the source string
jo!!!y
  ^  ^

Of course, if array1 is shorter than the matching string, you'll need to do the opposite and fill in the hole that's already there:

# Find "oe"
joey
 ^

# Shift everything after "oe" to fill in excess hole
joy
  ^

# Fill in the remaining hole with '!'
j!y
  ^

Don't forget to properly move your null character as well.

Joey_Brown commented: great help!! +1
Narue 5,707 Bad Cop Team Colleague

Wow, that behavior reeks of malware.

Narue 5,707 Bad Cop Team Colleague

ref class does not have a user-defined copy constructor

I bet you're using stack semantics with a copy constructor expecting managed references:

using namespace System;

ref class example {
public:
    example()
    {
        Console::WriteLine("Default constructor");
    }

    example(const example^ ref)
    {
        Console::WriteLine("Reference copy contructor");
    }
};

int main(array<String ^> ^args)
{
    example a;
    example b = a; // Uh-oh, no copy constructor for stack semantics
}

This can be fixed by converting the object to a reference handle, which will call the correct copy constructor:

example b = %a;

Or you can support both managed references and stack semantics in the copy constructor:

using namespace System;

ref class example {
public:
    example()
    {
        Console::WriteLine("Default constructor");
    }

    example(const example% obj)
    {
        Console::WriteLine("Stack copy constructor");
    }

    example(const example^ ref)
    {
        Console::WriteLine("Reference copy contructor");
    }
};

int main(array<String ^> ^args)
{
    example a;
    example b = a; // Now it works
    example d = gcnew example(); // This works too
}
MasterGberry commented: Perfect +0
Narue 5,707 Bad Cop Team Colleague

does it take a lot of planning to get an idea of the classes etc needed for a large application?

Yes, but my idea of a large application is probably very different from yours. For example, your blackjack game example would be small to me.

What kind of time frame?

It depends on the scale of the project, the size of the development team, and client participation.

I think I have it in my head, that because small programs are so easy to write, and I can "make it up" as I go along, I therefore think large applications must be the same.

As the scale of a project increases, the rules change. So no, large programs are not the same as small programs. Fresh college graduates who think they're invincible geniuses are often chagrined when they face reality. ;)

Narue 5,707 Bad Cop Team Colleague

What is google?

Narue 5,707 Bad Cop Team Colleague

Catching up is not as difficult as starting.

How many people have you helped unlearn bad habits from Turbo C? I've helped hundreds, and my experience is that it's harder than learning modern C from the get go.

i have a compiler but it is not compatible to my OS (windows7).

Visual C++ 2010 Express
Code::Blocks
Pelles C
LCC-Win32

Narue 5,707 Bad Cop Team Colleague

Why in the world do you need to create a TSR? Those are about twenty years obsolete, and pretty much only usable on a true DOS system.