re: 我的程序人生[未登錄] 史傳紅 2007-01-24 14:00
樓主對軟件領域的涉足很廣泛,而且有點領域也很精深,是我學習的楷模啊。
re: 計算Int最大最小值 史傳紅 2006-12-04 09:24
很好。
re: 并行編程--MPI開發入門 史傳紅 2006-06-12 20:12
我現在也在搞這方面的研究,不過是在linux系統下,多多向你學習。
re: 五一就要回家嘍 史傳紅 2006-05-15 14:24
謝謝,我是吉林大學(朝陽校區)畢業的。
re: 母親節快到了,寫點東西送給母親 史傳紅 2006-05-12 20:33
謝謝大家的祝福.我是安徽六安市霍邱縣眾興鄉洪崗村中心隊人(夠詳細的吧,呵呵).
@小東
相信只要努力了,我們一定都會有所收獲的.此外我也算是一個比較幸運的人而已.相信有很多朋友比我更努力,但是過得比我還艱難...
re: 母親節快到了,寫點東西送給母親 史傳紅 2006-05-12 17:01
謝謝大家的鼓勵,我會一直盡力努力下去的.
re: 發現一個免費打網絡電話的方法。 史傳紅 2006-05-11 13:24
最好,就是你安裝一個電子郵件服務器軟件。這下,你想打多長時間,就打多長時間。
請問它和電子郵件服務器怎么聯系上的?如何設置?謝謝.
原因不是*this不能轉換成const vector3D&,而是常成員函數(double angle() const)不能調用 非 常成員函數(double dotP(const Vector3D& v1,const Vector3D& v2)),如果把dotp改成如下定義:double dotP(const Vector3D& v1,const Vector3D& v2) const.
問題就解決了.
re: 漫談函數的返回值 史傳紅 2006-05-03 23:01
@<font color="#FF00FF" >Stone Jiang
希望是這樣的.
re: 關于語句作用域 史傳紅 2006-05-03 10:30
是的,標準規定了for(int i=0;i<10;i++)中的i只在語句內有效,可見。
我覺得用string時間快的原因可能跟這句:char *pc2= new char[len+1];
有關。庫在處理string時候可能有某種優化,使得處理時間快些。也就是不同的系統在優化 string str2=str; 的時候可能不一樣,所以windows系統沒有占到優勢。
@flyingxu
由于我以前遇到這個問題沒有解決,現在看了深入淺出MFC這本書,總結出來的,你能給出一個好的結構嗎?我的意思是說把文檔的數據在一個對話框中實時表現出來,謝謝。
re: c++程序員 常用工具集 史傳紅 2006-04-24 13:33
版本控制現在比較不錯的是 svn.
@Stone Jiang
能把這篇文章貼出來嗎?我打開連接發現是好多主題。謝謝。
@roa420
我在Visual C++ 6.0中編譯的時候也出現過問題,我懷疑它對友元支持的不好。
建議你換一個編譯器試試看。
re: 關于C++模板函數的問題 史傳紅 2006-04-12 14:11
原來是我和標準模板庫的函數重名了。通過改成:
template <class T>
const T& my_max(const T& a,const T& b)
{
return a > b ? a : b;
}
const float f = my_max(1.5f,2.5f);
就沒有問題了。
看到了樓主的這篇文章,我試著改了一下,如下:希望大家一起加入討論。
#include <iostream>
using namespace std;
class Matrix
{
private:
int rows,columns;
int **pMatrix;
public:
Matrix(int rows = 3,int columns = 2);
Matrix(const Matrix &M);
~Matrix();
Matrix& operator=(const Matrix& M);
int GetRows() const;
int GetColumns() const;
void SetValue();
friend Matrix operator*(const Matrix& a,const Matrix& b);
friend ostream& operator<<(ostream& os,const Matrix& M);
};
int Matrix::GetRows() const { return rows;}
int Matrix::GetColumns() const { return columns;}
// 構造函數
Matrix::Matrix(int x,int y)
{
rows = x;
columns = y;
//有的時候為了考慮創建對象的效率,在使用的時候分配存儲空間,而不在構造函數中分配
pMatrix = new int* [x];
for (int i = 0 ; i < x; i++ )
{
pMatrix[i] = new int[y];
for(int j = 0;j < y;j++) //初始化每個值為0
pMatrix[i][j] = 0;
}
}
// 析構函數
Matrix::~Matrix()
{
for (int i = 0 ;i < rows;i ++ )
delete[] pMatrix[i];
delete[] pMatrix;
}
// 賦值函數
Matrix& Matrix::operator=(const Matrix& M)
{
if(this != &M)
{
for (int ii = 0 ;ii < rows;ii++ )
if(pMatrix[ii])
delete[] pMatrix[ii];
if(pMatrix)
delete[] pMatrix;
rows = M.rows;
columns = M.columns;
//分配存儲空間
pMatrix = new int* [rows];
for (int k = 0 ; k < rows; k++ )
pMatrix[k] = new int[columns];
for ( int i = 0 ; i < rows; i ++ )
for ( int j = 0 ; j < columns; j ++ )
pMatrix[i][j] = M.pMatrix[i][j];
}
return *this;
}
void Matrix::SetValue()
{
int i,j,value;
for ( i = 0 ; i < rows; i ++ )
{
for ( j = 0 ; j < columns; j ++ )
{
cout << " 第 " << i << " 行 " ;
cout << " 第 " << j << " 列: " ;
cin >> value;
cout << endl;
pMatrix[i][j] = value;
}
}
}
// 拷貝構造函數
Matrix::Matrix(const Matrix& M)
{
rows = M.rows;
columns = M.columns;
//分配存儲空間
pMatrix = new int* [rows];
for (int k = 0 ; k < rows; k++ )
pMatrix[k] = new int[columns];
for ( int i = 0 ; i < rows; i ++ )
for ( int j = 0 ; j < columns; j ++ )
pMatrix[i][j] = M.pMatrix[i][j];
}
Matrix operator*(const Matrix& a,const Matrix& b)
{
if (a.columns == b.rows)
{
Matrix c(a.rows,b.columns);
for ( int i = 0 ;i < a.rows;i ++ )
{
for ( int j = 0 ;j < b.columns;j ++ )
{
for ( int columnIndex= 0 ;columnIndex < a.columns;columnIndex++ )
c.pMatrix[i][j] += a.pMatrix[i][columnIndex] * b.pMatrix[columnIndex][j];
}
}
return c;
}
else
return Matrix();
}
ostream& operator<<(ostream& os,const Matrix& M)
{
for (int i = 0;i < M.rows;i++ )
{
for (int j = 0;j < M.columns;j++ )
os << M.pMatrix[i][j] << " ";
os << endl;
}
return (os << endl);
}
// 主函數
void main()
{
Matrix Ma(3,2),Mb(2,2);
Ma.SetValue();
Mb.SetValue();
cout << Ma << endl;
cout << Mb << endl;
Matrix Mc = Ma * Mb;//拷貝構造函數
cout << Mc << endl;
Mc = Mb; //=運算符,即賦值函數
cout << Mb << endl;
}
re: C++跨平臺開發方法/工具 史傳紅 2006-04-06 18:16
我覺得在一臺機器上擁有兩個系統,速度是相當慢的,我深有體會.我目前用的兩種方法,覺得效率挺高:
1.用putty這個軟件從windows登陸linux系統,然后在windows里面用UltraEdit編寫源代碼.通過putty在linux系統編譯和執行.
2.用BVRDE這個軟件就可以做到在windows下面做linux開發,它只是一個IDE,所用的文件,編譯器和調試器等都在linux系統上面.下載網址:
http://bvrde.sourceforge.net/index.htm