Error C2447, C2143, C2059: Basic Visual C++ Class Definition
I'm just trying to create a class in visual C++ but keep getting the three errors mentioned above:
Line 9: error C2447:
Line 9: error C2143: syntax error : missing'{'
: missing function header (old-style formal list?) in UIAutomationCPP.cpp';'
before'{'
in UIAutomationCPP.cpp Line 9: error C2059: syntax error :')'
in UIAutomationCPP.cpp
My code for the project is as follows:
// File Name: AutomationCPP.h
#pragma once
#ifndef AUTOMATIONCPP_H
#define AUTOMATIONCPP_H
#include "Stdafx开发者_开发知识库.h"
using namespace System;
namespace AutomationCPP
{
public ref class CustomAutomationCPP
{
public:
CustomAutomationCPP();
int first;
private:
int second;
};
}
#endif
And the class .cpp file:
// File Name: AutomationCPP.cpp
#include "Stdafx.h"
#include "AutomationCPP.h"
using namespace System;
AutomationCPP::CustomAutomationCPP()
{
}
Please help! I feel if I can get past this, the rest should be much easier.
A constructor is a special member function:
AutomationCPP::CustomAutomationCPP::CustomAutomationCPP()
{
}
Alternatively to Etienne's, which I find personally more readful as it removes some noise from the members:
namespace AutomationCPP {
CustomAutomationCPP::CustomAutomationCPP()
{
}
void CustomAutomationCPP::foo()
{
}
// ...
} // namespace AutomationCPP
精彩评论