あなたのメインは少し分厚いです。
int main(){
classname(20, 20) object; // You are incorrectly calling a constructor which does not exist
object.classfunction2(50, 50); // more like correct behavior.
}
あなたが定義したクラスは、すべてのメンバ変数を持っていないので、それはないstore
任意のデータを行います。これには2つの機能しかありません。したがって、これは、コンパイラがすべてのクラスに対して定義する "デフォルトのコンストラクタ"を使用できることを意味します(必要に応じて独自に提供できます)。
int main(){
classname object; // Call the default constructor
object.classfunction1(10, 20); // Call the functions you want.
object.classfunction2(50, 50);
}
あなたが何かやるべきコンストラクタを提供したい場合:
int main(){
classname object(10, 20); // Call the default constructor. Note that the (10, 20) is AFTER "object".
object.classfunction1(); // Call the function... it will use 10 and 20.
object.classfunction2(50, 50); //This function will use 50, 50 and then call classfunction1 which will use 10 and 20.
}
注意すべき物事のカップル:道
class classname{
public:
classname(int variable1, int variable2):
member1(variable1), member2(variable2){}; //note that there is no return type
void classfunction1(); //because instead of taking parameters it uses member1 & 2
void classfunction2(int, int);
private:
int member1;
int member2;
};
をメインあなたはその後、次のようになります最初のコンストラクターを呼び出そうとしましたが、変数名の後にパラメーターが必要です。 下記のコメントを見て、もう一度注意してください。
私はそれがあなたが達成しようとしていることを理解するのに苦労しています、あなたの疑似コードは実際には意味がありません、申し訳ありません。あなたはコンストラクタを書く方法を探していますか? – Mat