Sci@phy 97 Posting Whiz in Training

Post entire code please. Once more :)

Sci@phy 97 Posting Whiz in Training
typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{	
	Vec1 Row; 
	for( int i = 0; i < 1000; i++ )
	{
                Row.Add("0");
         }
         
          List1.Add(Row);
}

List1[3][3] = "Hello";

It should be something like this :)

Sci@phy 97 Posting Whiz in Training

Well, it says about 'n' not being initialised. Try to debug it yourself!

Sci@phy 97 Posting Whiz in Training

On line 7 you have:

int power (int n); // function prototype

And later you call your function:

float power(float a, int n)
Sci@phy 97 Posting Whiz in Training

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

typedef vector<string> row;

vector<row> *vec1 = new vector<row>;
Sci@phy 97 Posting Whiz in Training

I belive it stores array of strings (all read froom same line, but separated with Delimiter), but am not sure. Try it

Sci@phy 97 Posting Whiz in Training

Isn't negative factorial kind of wrong altogether?

Sci@phy 97 Posting Whiz in Training

Found this using google: Example

1  
   2    private void ImportCountries()
   3    {
   4      string delimiter = ",";
   5      string fileName = @"c:\countrylist3.csv";
   6  
   7      StreamReader sr = new StreamReader(fileName);
   8  
   9      try
  10      {
  11        while (sr.Peek() >= 0)
  12        {
  13          string r = sr.ReadLine();
  14          string[] items = r.Split(delimiter.ToCharArray());
  15        }
  16      }
  17      finally
  18      {
  19        sr.Close();
  20      }
  21    }
  22
Sci@phy 97 Posting Whiz in Training

I don't see a problem. You don't need this piece of code:

{
int old_number= 0;
int current_number = 1;
int next_number;

}
Sci@phy 97 Posting Whiz in Training

Here's what you have to do:

# include<iostream>

using namespace std;

int main()
{
    int i;
    
    cout << "Please enter the size of square: ";
    cin >> i;
   for(int col=0; col<i; col++) 
   {    
       cout <<endl<<endl;
       
       for(int row=0; row<i; row++)
           {
             if((col==0 || col==i-1) || (row==0) || (row ==i-1))  
             {                                                              
               cout << " * ";
             }
             else cout<<"   ";
               
           }
   }
    system("pause");
    return 0;
    
}

First, notice my for-loops (row and col, both start from 0, not 1)
It doesn't affect program, but it's the more "normal" way in c++ :)

Second, what was your problem:
you didn't have else condition. Then, when if failed, nothing happened.
But now if "if" fails, a blank space is typed.
HTH

Sci@phy 97 Posting Whiz in Training

I don't see why there should be any difference. When you write:

void MyClass Func (const MyClass f)
//or even simply:
const MyClass f(some_MyClass_obj);

And let's say we call Func:

Func(some_other_MyClass_obj);

What happens? First let's see what happens in a function:
1. We put in a Func "some_other_MyClass_obj".
2. Program calls constructor to construct "f", a local object inside Func
3. Constructor is checking what are you giving to him. He is checking if "some_other_MyClass_obj" is of type const MyClass or simply MyClass, and then calls proper constructor function.
He doesn't care about line "const MyClass f", because after the "f" is constructed, it will be given const-ness.
4. f is made, and is given his const-ness.


OK, what happens in your recent functions, I'll try to explain.
You have a member function doSomething. That function takes MyClass as argument, and it can change it.
Of course you get error when you try to change f inside your non-member function, that's because f is const! But the important thing is that the const-ness is given AFTER constructor (it's obvious, because constructor HAS to change object!)
And the only thing that distincts your two constructors (for post before) is that one accepts one type of argument, and the other one accepts other type of argument.

VernonDozier commented: helpful +7
Sci@phy 97 Posting Whiz in Training
int return1 (int n);

Why is that semicolon there??? Delete that! Syntax error

ssharish

And why is it called return1??? It should be fact!!!

Sci@phy 97 Posting Whiz in Training

Ok, I have an idea, but am not sure 100%.

When you write:

void Func (const MyClass g)

You say to compiler: MyClass g (I changed a name from f, but it's irrelevant) will not change!

But, that const keyword is irrelevant of calling constructor.
When you write:

MyClass (const MyClass& f)

You say to compiler: This constructor is going to GET object of type: const MyClass!

When you write inside a main function:

MyClass a(3);
const MyClass b(a);
MyClass c(a);

Func(3); //you are calling int constructor that will create const MyClass g(3)
Func(b); //you are calling const constructor, that will create const MyClass g(b) because b is const
Func(c); //you are calling non-const constructor that will create const MyClass g(c) because c is non-const!
Sci@phy 97 Posting Whiz in Training

This is actually very interesting. Well, first thing, i managed to call const constructor by doing this to main:

int main ()
{
    const MyClass f(4);
    cout << "In main before Func call: f.x = " << f.x << endl;
    Func (f);
    cout << "In main after Func call: f.x = " << f.x << endl;
    cin.get();
    return 0;
}

So, if u pass const object to Func, it will obviously trigger const constructor.

I'll post if i find out something new :)

Sci@phy 97 Posting Whiz in Training

If you want to be able to write

something = 4 + var;

You have to overload once more operator+.

First, declare it as friend of class, and then write it like:

Array<T> operator+ (const float f, Array<T> myVal);

That's because if you define operator+ as a member of class it is interpretting:
val + 3;
as:
val.operator+(3);
So if you write:
3 + val;
it is interpretted as:
3.operator+ //it's clearly rubbish

monkey_king commented: Very helpfull +1