Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3046

structure with function pointers

$
0
0
Hi,
compiled the following code with visual studio 2102 and got an error in the red line.

Code:

#include "stdafx.h"
#include <iostream>


struct MyStruct {
        int (*foo)();
};


static int func1()
{
        printf("I am called\n");
        return 0;
}


static struct MyStruct a = {
        .foo = func1 //getting error here as shown below
};


int main()
{
        a.foo();
        return 0;
}

Error    1    error C2143: syntax error : missing '}' before '.'   
Error    2    error C2143: syntax error : missing ';' before '.'   
Error    3    error C2059: syntax error : '.'   
Error    4    error C2143: syntax error : missing ';' before '}'   
Error    5    error C2059: syntax error : '}'   
    6    IntelliSense: expected an expression


Viewing all articles
Browse latest Browse all 3046

Trending Articles