Click here to Skip to main content
15,913,154 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: create a constructor for a struct Pin
James R. Twine21-Dec-06 8:42
James R. Twine21-Dec-06 8:42 
GeneralRe: create a constructor for a struct Pin
David Crow21-Dec-06 8:53
David Crow21-Dec-06 8:53 
GeneralRe: create a constructor for a struct Pin
James R. Twine21-Dec-06 9:16
James R. Twine21-Dec-06 9:16 
GeneralRe: create a constructor for a struct Pin
markkuk21-Dec-06 5:47
markkuk21-Dec-06 5:47 
AnswerRe: create a constructor for a struct Pin
VonHagNDaz21-Dec-06 5:32
VonHagNDaz21-Dec-06 5:32 
AnswerRe: create a constructor for a struct Pin
krmed21-Dec-06 5:48
krmed21-Dec-06 5:48 
GeneralRe: create a constructor for a struct Pin
cy163@hotmail.com21-Dec-06 5:59
cy163@hotmail.com21-Dec-06 5:59 
GeneralRe: create a constructor for a struct [modified] Pin
krmed21-Dec-06 7:00
krmed21-Dec-06 7:00 
I believe for what you're trying to do, you'll need this (note there are two constructors here - one with no parameters and the one you are trying to use):
struct Stru_A{
    char Name[30];
    int Age;
    Stru_A::Stru_A() 
    {
        memset(Name, 0, 30);
        Age = 0;
    }

    Stru_A::Stru_A(char* inName, int inAge) 
    {
        memset(Name, 0, 30);    // this insures a null terminator
        strncpy(Name, inName, 29);
        Age = inAge;
    }
}*pStru_A;

pStru_A xyz = new Stru_A("ABC", 123);


Note also that you should use strncpy to be sure the copy doesn't overwrite the 30 character size you have, and still leaves space for the null terminator.

Hope that helps.


-- modified at 16:32 Thursday 21st December, 2006

Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

GeneralRe: create a constructor for a struct Pin
James R. Twine21-Dec-06 8:48
James R. Twine21-Dec-06 8:48 
GeneralRe: create a constructor for a struct Pin
krmed21-Dec-06 9:13
krmed21-Dec-06 9:13 
GeneralRe: create a constructor for a struct Pin
James R. Twine21-Dec-06 9:18
James R. Twine21-Dec-06 9:18 
AnswerRe: create a constructor for a struct Pin
Michael Dunn21-Dec-06 9:55
sitebuilderMichael Dunn21-Dec-06 9:55 
QuestionCombo Box Order question Pin
Like2Byte21-Dec-06 4:20
Like2Byte21-Dec-06 4:20 
AnswerRe: Combo Box Order question Pin
CPallini21-Dec-06 4:30
mveCPallini21-Dec-06 4:30 
GeneralRe: Combo Box Order question Pin
Like2Byte21-Dec-06 4:52
Like2Byte21-Dec-06 4:52 
GeneralRe: Combo Box Order question Pin
CPallini21-Dec-06 8:00
mveCPallini21-Dec-06 8:00 
AnswerRe: Combo Box Order question Pin
Maximilien21-Dec-06 4:34
Maximilien21-Dec-06 4:34 
GeneralRe: Combo Box Order question Pin
CPallini21-Dec-06 4:45
mveCPallini21-Dec-06 4:45 
AnswerRe: Combo Box Order question Pin
David Crow21-Dec-06 4:53
David Crow21-Dec-06 4:53 
GeneralRe: Combo Box Order question Pin
Like2Byte21-Dec-06 4:59
Like2Byte21-Dec-06 4:59 
QuestionMaximizingEnd Pin
baerten21-Dec-06 3:39
baerten21-Dec-06 3:39 
AnswerRe: MaximizingEnd Pin
CPallini21-Dec-06 3:55
mveCPallini21-Dec-06 3:55 
GeneralRe: MaximizingEnd Pin
baerten21-Dec-06 4:04
baerten21-Dec-06 4:04 
AnswerRe: MaximizingEnd Pin
James R. Twine21-Dec-06 4:01
James R. Twine21-Dec-06 4:01 
GeneralRe: MaximizingEnd Pin
baerten21-Dec-06 4:27
baerten21-Dec-06 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.