程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> [RK_2014_1020]Cannot declare member function ‘static int Foo::bar()’ to have static linkage,declarefunction

[RK_2014_1020]Cannot declare member function ‘static int Foo::bar()’ to have static linkage,declarefunction

編輯:C++入門知識

[RK_2014_1020]Cannot declare member function ‘static int Foo::bar()’ to have static linkage,declarefunction


1.

if you declare a method to be static in your .cc file.

The reason is that static means something different inside .cc files than in class declarations It is really stupid, but the keyword static has three different meanings. In the .cc file, the static keyword means that the function isn't visible to any code outside of that particular file.

This means that you shouldn't use static in a .cc file to define one-per-class methods and variables. Fortunately, you don't need it. In C++, you are not allowed to have static variables or static methods with the same name(s) as instance variables or instance methods. Therefore if you declare a variable or method as static in the class declaration, you don't need the static keyword in the definition. The compiler still knows that the variable/method is part of the class and not the instance.

WRONG

 Foo.h:
 class Foo 
 {
   public: 
     static int bar();
 };
 Foo.cc:
 static int Foo::bar() 
 {
   // stuff
 }

WORKS

 Foo.h:
 class Foo 
 {
   public: 
     static int bar();
 };
 Foo.cc:
 int Foo::bar() 
 {
   // stuff
 }

A way to bypass this problem is to embed the defintion in the .h file, but this causes the function to be inline by default.

ALSO WORKS

 Foo.h:
 class Foo 
 {
   public: 
     static int bar()
       {
         // stuff
       };
 };

 

2.

test.cpp:285: cannot declare member function `static int
   CTest::testEtrance(short unsigned int)' to have static linkage

 

錯誤的原因就是在實現的地方不需要static了, 只在聲明的地方需要static

static int CTest::testEtrance(WORD  wCaseNO)

{

}

static 是多余的, 把static刪除就可以解決這樣的編譯錯誤.

 

3.本文網址[tom-and-jerry發布於2014-10-20 18:02]

http://www.cnblogs.com/tom-and-jerry/p/4037965.html 


function D=height(C) C=double(C) %將二值圖像C的類型轉化為double型 [Height,Width] = size(C); %計算圖

#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK ScrollProc(HWND, UINT, WPARAM, LPARAM);

int idFocus;
WNDPROC OldScroll[3];

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; ......余下全文>>
 

怎:用反射發出定義泛型方法

第二個過程演示如何發出方法體,以及如何使用泛型方法的類型參數創建泛型類型的實例以及調用其方法。 第三個過程演示如何調用泛型方法。 重要事項 不能僅因為某個方法屬於泛型類型且使用泛型類型的類型參數,就稱該方法是泛型方法。 只有當方法具有自己的類型參數列表時,才能稱其為泛型方法。 泛型方法可以出現在非泛型類型上,在本例中就是如此。 有關泛型類型上的非泛型方法的示例,請參見 如何:用反射發出定義泛型類型。 定義泛型方法 首先,如果使用高級語言編寫,則查看泛型方法的顯示方式會十分有用。 下面的代碼包含在此主題的代碼示例中,用於調用泛型方法的代碼同樣也包含在其中。 該方法具有兩個類型參數 TInput 和TOutput,後者必須為引用類型 (class),必須具有無參數構造函數 (new),並且必須實現 ICollection(Of TInput)(在 C# 中為 ICollection<TInput>)。 此接口約束確保 ICollectionTAdd 方法可用於將元素添加到該方法創建的 TOutput 集合中。 該方法具有一個形參 input,這是一個 TInput 的數組。 該方法創建類型 TOutput 的集合,並將 input 的元素復制到該集合中。 Public Shared Function Factory(Of TInput, _ TOutput As {ICollection(Of TInput), Class, New}) _ (ByVal input() As TInput) As TOutput Dim retval As New TOutput() Dim ic As ICollection(Of TInput) = retval For Each t As TInput In input ic.Add(t) Next Return retval End Function public static TOutput Factory<TInput, TOutput>(TInput[] tarray) where TOutput : class, ICollection<TInput>, new() { TOutput ret = new TOutput(); ICollection<TInput> ic = ret; foreach (TInput t in tarray) { ic.Add(t); } return ret; } 定義一個動態程序集和一個動態模塊,以包含該泛型方法所屬的類型。 在本例中,該程序集僅擁有一個模塊(名為 DemoMethodBuilder1),模塊名稱即為程序集名稱加上一個擴展名。 在此示例中,將程序集保存到磁盤中並執行,因此指定了 AssemblyBuilderAccessRunAndSave。 您可以使用 Ildasm.exe(MSIL 反匯編程序) 檢查DemoMethodBuilder1.dll,並將其與步驟 1 中顯示的方法的 Microsoft 中間語言 (MSIL) 進行比較。 Dim asmName As New AssemblyName("DemoMethodBuilder1") Dim domain As AppDomain = AppDomain.CurrentDomain Dim demoAssembly As AssemblyBuilder = _ domain.DefineDynamicAssembly(as......余下全文>>
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved