Click to See Complete Forum and Search --> : [RESOLVED] CArray - what is wrong with this one?


nanandavalli
June 12th, 2006, 01:47 AM
There are two classes. One with name CTest and another with name CMember. CTest contains an array of type CMember. I tried to add members to this array using the following code:

Test.cpp contains

#
# // Test.cpp : implementation file
# //
# #include "stdafx.h"
# #include "array.h"
# #include "Test.h"
# #include "Member.h"
#
# // CTest
#
# IMPLEMENT_DYNAMIC(CTest, CWnd)
#
# CTest::CTest()
# {
#
# }
#
# CTest::~CTest()
# {
# }
# void CTest::assignvalue()
# {
# CMember cm;
# testarray.SetSize(10,-1);
# for(int i=0;i<10;i++){
# cm.value(i*10.0);
# cm.num(i);
# testarray.SetAt(i,CMember(cm));
# }
# }
# void CTest::printvalue()
# {
# char str[50];
# for(int i=0;i<10;i++){
# sprintf(str,"%d %lf",testarray[i].num(),testarray[i].value());
# printf("\n%s",str);
# }
# }
# BEGIN_MESSAGE_MAP(CTest, CWnd)
# END_MESSAGE_MAP()
# // CTest message handlers

Test.h contains

# #pragma once
# #include "Member.h"
#
# // CTest
#
# class CTest : public CWnd
# {
# DECLARE_DYNAMIC(CTest)
# private:
# CArray<CMember,CMember> testarray;
# public:
# void assignvalue();
# void printvalue();
# CTest();
# virtual ~CTest();
#
# protected:
# DECLARE_MESSAGE_MAP()
# };

Member.h contains

# #pragma once
# // CMember
# class CMember : public CWnd
# {
# DECLARE_DYNAMIC(CMember)
# private:
# int nnum;
# double fvalue;
# public:
# CMember();
# void num(int nnum);
# void value(double fvalue);
# int num();
# double value();
# virtual ~CMember();
#
# protected:
# DECLARE_MESSAGE_MAP()
# };

What is wrong in the code?